CSS 设置背景色指定高度

CSS 设置背景色指定高度,我们通过 ::before 或者 ::after伪类来实现。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <title>css 设置指定高度背景色</title>
  <style type="text/css">
p {
   display: inline-block;
   position: relative;
}
p::before {
   content: '';
   position: absolute;
   bottom: 0;
   left: 0;
   width: 100%;
   height: 50%;
   background: rgba(255, 187, 68, 0.2);
}
  </style>
</head>

<body>
  <p>我的背景颜色指定高度50%</p>
</body>
</html>

CSS设置背景色指定高度的方法_零五网