1. :before和 :after
CSS中的:befor、:after都会创建一个伪元素,其中:befor创建的伪元素是所选元素的第一个子元素,:after创建的伪元素是所选元素的最后一个子元素。
:befor、:after创建的伪元素**默认样式为内联样式**。
(1)`注意:CSS3引入了 ::(两个冒号)是用来区分伪类(:一个冒号)和伪元素(::两个冒号)。
- 伪类:操作元素本身,如 :hover、:first-child、:focus等等。
- 伪元素:操作元素的子元素,如 ::before、::after、::content等等。
(2)content属性
content 属性表示伪元素填充的内容。
css部分:
.a {
width: 100px;
height: 100px;
margin-left: 20px;
background-color: #eee;
}
.a::before {
content: "♥";
color: red;
}
.a::after {
content: "♥";
color: blue;
}
html部分:
<div class="a">
"hello"
</div>