gpt4 book ai didi

html - 伪元素 background-image 不起作用

转载 作者:行者123 更新时间:2023-11-28 02:06:41 25 4
gpt4 key购买 nike

根据 other SO solutions , 我已经尝试为伪元素提供明确的固定尺寸 (height: X px; width: X px;) 但即使这可行,我也想要一个适合其父元素的可缩放响应图像,因此,固定尺寸对我来说是 Not Acceptable 。如何让 background-image 显示并同时自动缩放?

HTML:

<h3>This is a title</h3>

CSS:

 h3:before{
background-image:url('https://store.ashenglowgaming.com/wp-content/uploads/2018/02/cropped-agg-store-logo-4-FULLSIZE-1.jpg');
background-size: contain;
background-repeat: no-repeat;
display: block;
}

最佳答案

试试这个

h3:before{
background-image: url(https://store.ashenglowgaming.com/wp-content/uploads/2018/02/cropped-agg-store-logo-4-FULLSIZE-1.jpg);
background-size: contain;
background-repeat: no-repeat;
content: '';
height: 110px;
display: block;
}

关于html - 伪元素 background-image 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48982250/

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