為什么我的偽元素 ::before 不起作用?我有一個嵌套在其中的元素,但它不起作用。我在 VSCode 上使用實時預覽擴展,當我按下“f12”時,沒有 ::before。
這是代碼
HTML
<div class="image">
<img
src="https://images.unsplash.com/photo-1542831371-29b0f74f9713?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8cHJvZ3JhbW1lcnxlbnwwfHwwfHw=&auto=format&fit=crop&w=500&q=60"
alt="Código de Programa??o"
/>
</div>
和CSS
#home .image::before {
content: 'asdasd';
height: 100%;
width: 100%;
background: rgb(92, 226, 43);
position: absolute;
top: -16.8%;
left: 16.7%;
z-index: 1;
}
uj5u.com熱心網友回復:
.image您的測驗頁面中是否有 div之外的元素?::before如果我這樣做,我可以看到。
#home .image::before {
content: 'asdasd';
height: 100%;
width: 100%;
background: rgb(92, 226, 43);
position: absolute;
top: -16.8%;
left: 16.7%;
z-index: 1;
}
<div id="home">
<div class="image">
<img src="https://images.unsplash.com/photo-1542831371-29b0f74f9713?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxzZWFyY2h8M3x8cHJvZ3JhbW1lcnxlbnwwfHwwfHw=&auto=format&fit=crop&w=500&q=60" alt="Código de Programa??o" />
</div>
</div>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/468997.html
