gpt4 book ai didi

css - 无法在位置绝对 div 上添加背景图片

转载 作者:太空宇宙 更新时间:2023-11-04 11:40:20 25 4
gpt4 key购买 nike

你能看看this demo吗?让我知道为什么我无法将图像添加到 #img-box

html, body {
height:100%;
width:100%;
}
#wrapper {
position: relative;
height: 100%;
width: 100%;
}
#img-box {
position: absolute;
background-image: url("http://www.bluearthrenewables.com/wp-content/uploads/2014/12/7_Intake-Construction_CullitonCreek.jpg");
top:0;
left:0;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}

最佳答案

因为 #img-box 没有任何与之关联的宽度和高度。尝试定义

html, body {
height:100%;
width:100%;
}
#wrapper {
position: relative;
height: 100%;
width: 100%;
}
#img-box {
position: absolute;
background-image: url("http://www.clker.com/cliparts/2/0/f/b/13873752061098664878happy_smiley-th.png");
height: 100%;
width: 100%;
top:0;
left:0;
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed;
}
<div id="wrapper">
<div id="img-box"></div>
<div id="tets"></div>
<div id="tes3"></div>
</div>

关于css - 无法在位置绝对 div 上添加背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31393687/

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