gpt4 book ai didi

css - :after pseudo class doesn't insert background image

转载 作者:太空宇宙 更新时间:2023-11-03 23:19:47 24 4
gpt4 key购买 nike

当我使用 :after pseudo class with background image 时,它没有显示在我的 div 中。为什么会这样?

附言当我应用 position:absolute top:0, right:0 时,我可以看到图像。

<div class="vienas">abra kadabra</div>
.vienas {
height:200px;
border: 1px solid black;
position: relative;
}

div::after {
content:" ";
background: url(http://www.apicius.es/wp-content/uploads/2012/07/IMG-20120714-009211.jpg);
width:100px;
height: 100px;
}

最佳答案

默认情况下,伪元素设置为显示内联。因此,您的 widthheight 属性不会对元素产生任何影响,而是默认为内部内容的宽度和高度。

您需要将其设置为display: block:

div::after {
...
display: block;
}

JSFiddle demo .

关于css - :after pseudo class doesn't insert background image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com