使用场景: 页面中非主要元素可以使用伪元素
伪元素有两个:
::before 在父元素内容的最前面添加一个伪元素
::after 在父元素内容的最后面添加一个伪元素
在伪元素的使用中,必须添加content属性,不然伪元素不生效
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father {
width:300px;
height: 300px;
background-color: pink;
}
.father::before {
content: '老鼠';
color: green;
}
.father::after {
content: '爱大米';
}
</style>
</head>
<body>
<div class="father">爱</div>
</body>
</html>