伪元素选择器before和after
<!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>伪元素选择器before和after</title>
<style>
div {
width: 200px;
height: 200px;
background-color: pink;
}
/* 权重是2,标签选择器加伪元素选择器=1+1=2 */
div::before {
/* 因为是行内元素,所以加宽和高是没用的,需要转换成块元素 */
display: block;
/* 这个content是必须要写的 */
content: '我';
width: 30px;
height: 40px;
background-color: purple;
}
div::after {
content: '小猪佩奇';
}
</style>
</head>
<body>
<div>是</div>
</body>
</html>