Skip to content

::before ​

描述 ​

::before 伪元素用于在添加它的元素的内容之前显示所需的文本。与内容属性结合使用。 对于 ::before ,以下特征是典型的。 1、块元素添加 ::before 时,display 属性的值只能是:block、inline、none、marker。所有其他值将被视为块。 2、在内联元素中添加 ::before 时,显示仅限于 inline 和 none。所有其他的都将被视为内联。 3、 ::before 继承其所添加到的元素的样式。

语法 ​

css
element::before {
  content: "text";
}

效果展示 ​