gpt4 book ai didi

html - 如何使背景图像填充 div 和响应

转载 作者:行者123 更新时间:2023-11-27 22:58:21 25 4
gpt4 key购买 nike

我想制作一个带有背景图片的 div,顶部会有 3 个社交媒体图标,如下所示:

我想要的: what i wanted

div#second-footer-container {
background-image: url("https://i.imgur.com/0qRwdSI.png");
width: 100% !important;
background-size: 100% 100%;
background-repeat: no-repeat;
height: 100%;
}

p#socmed-container {
text-align: center;
}

p#socmed-container a {
padding: 0 5px !important;
}
<div id="second-footer-container">
<p id="socmed-container">
<a href="https://www.facebook.com/test/">
<img id="fb-img" width="25" src="https://i.imgur.com/6ye5lwf.png" alt="Facebook" />
</a>
<a href="https://www.instagram.com/test/">
<img id="ig-img" width="25" src="https://i.imgur.com/SEsRzFL.png" alt="Instagram" />
</a>
<a href="https://www.twitter.com/test/">
<img id="twitter-img" width="25" src="https://i.imgur.com/y8o23cc.png" alt="Twitter" />
</a>
</p>
</div>

但是结果看起来不像我想要的,我的结果是背景似乎只跟随主要内容的高度: result

我希望宽度为 100%,高度也为 100%,并且我希望它具有响应能力

最佳答案

使用background-size:contain

Scales the image as large as possible without cropping or stretching the image.

background-size - reference

body,html{
height: 100%;
}
div#second-footer-container {
background-image: url("https://i.imgur.com/0qRwdSI.png");
width: 100% !important;
background-size: contain;
background-repeat: no-repeat;
height: 100%;
}

p#socmed-container {
text-align: center;
}

p#socmed-container a {
padding: 0 5px !important;
}
<div id="second-footer-container">
<p id="socmed-container">
<a href="https://www.facebook.com/test/">
<img id="fb-img" width="25" src="https://i.imgur.com/6ye5lwf.png" alt="Facebook" />
</a>
<a href="https://www.instagram.com/test/">
<img id="ig-img" width="25" src="https://i.imgur.com/SEsRzFL.png" alt="Instagram" />
</a>
<a href="https://www.twitter.com/test/">
<img id="twitter-img" width="25" src="https://i.imgur.com/y8o23cc.png" alt="Twitter" />
</a>
</p>
</div>

关于html - 如何使背景图像填充 div 和响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54194973/

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