在以下情况下,为什么:after选择器需要一个content属性才能起作用?
.test {
width: 20px;
height: 20px;
background: blue;
position:relative;
}
.test:after {
width: 20px;
height: 20px;
background: red;
display: block;
position: absolute;
top: 0px;
left: 20px;
}
注意,在没有指定content属性之前,你看不到伪元素。
.test {
width: 20px;
height: 20px;
background: blue;
position:relative;
}
.test:after {
width: 20px;
height: 20px;
background: red;
display: block;
position: absolute;
top: 0px;
left: 20px;
content:"hi";
}
为什么这是预期的功能?你可能会认为display:block会强制元素显示出来。奇怪的是,你实际上可以在Web调试工具中看到样式,但它们不会显示在页面上。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号