為什么:before和:after偽元素需要'content'屬性?鑒于以下場景,為什么:after選擇器需要內(nèi)容屬性才能運(yùn)行?.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;}<div class="test"></div>注意在指定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";}<div class="test"></div>為什么這是預(yù)期的功能?你會認(rèn)為顯示塊會強(qiáng)制元素出現(xiàn)。奇怪的是,您實(shí)際上可以在Web調(diào)試器中看到樣式; 但是,它們不會顯示在頁面上。
添加回答
舉報
0/150
提交
取消