伪元素before,after使用(如文本前的圆点)

发布时间 2023-12-04 10:26:59作者: 你风致

其实主要就是要定义content:"";

before或after会相对定义position:relative;最近的元素去定位;

比如实现一个文本前的黑色圆点:

p::before {
        content: "";
        width: 4px;
        height: 4px;
        background-color: #000;
        position: absolute;
        border-radius: 2px;
        top: 50%;
        left: 10px;
      }