gpt4 book ai didi

html - div 如何在 css 中填充父元素

转载 作者:太空宇宙 更新时间:2023-11-04 11:39:48 29 4
gpt4 key购买 nike

我有一个用于设置背景的 div,但我的输出显示该 div 未填充父级,它顶部仍有少量空白:
enter image description here

下面是我的代码:
HTML:

<body>
<div class="bg-image"></div>
<div class="center">
<div class="wrap">
<label>Welcome</label>
</div>
</div>
</body>


CSS:

.bg-image { 
position: absolute;
left: 0;
right: 0;
background-image: url(../images/background_blurred.jpg);
width: 100%;
height: 100%;
}
.center {
text-align: center;
z-index: 2;
}
.wrap {
position: absolute;
width: auto;
display: inline-block;
border: 3px solid #8AC007;
padding: 10px;
z-index: 2;
}

最佳答案

试试这个:

html,body{
margin:0;
padding:0;
}

.bg-image {
position: absolute;
left: 0;
right: 0;
top:0;
bottom:0;
background-image: url(../images/background_blurred.jpg);
}

关于html - div 如何在 css 中填充父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31437933/

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