gpt4 book ai didi

html - 为什么我的背景图片没有覆盖整个页面?

转载 作者:行者123 更新时间:2023-11-28 03:00:16 26 4
gpt4 key购买 nike

我希望我的背景图片覆盖整个 div,但有很多空白区域

HTML

<div class="backgroundsecction">
<div class="backgroundimg"></div>
</div>

CSS

.backgroundimg{
background-image: url(https://i.imgur.com/MAdBtV4.png);
height: 100%;
width: 100%;
background-repeat: no-repeat;

position: relative;
}


.backgroundsecction{
height: 900px;
width: 100%;

}

最佳答案

请使用background-size:cover

.backgroundimg{
background-image: url(https://i.imgur.com/MAdBtV4.png);
height: 100%;
width: 100%;
background-repeat: no-repeat;
position: relative;
background-size:cover;
}
.backgroundsecction{
height: 900px;
width: 100%;
}
<div class="backgroundsecction">
<div class="backgroundimg"></div>
</div>

关于html - 为什么我的背景图片没有覆盖整个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46250083/

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