gpt4 book ai didi

javascript - Div 背景图片最大尺寸

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:12 26 4
gpt4 key购买 nike

我在设置 div 中背景图片的最大高度时遇到了一些问题。最大高度应该是图像的高度,不能大于该高度。如果 div 中的内容太多,它只是放大图像。当背景图像结束时,我希望它继续为我的其余内容使用背景颜色。这是我试过的代码

<style>
.profilbg {
background: url(<?php echo $uin->backgroundimg; ?>);
background-repeat: no-repeat;
background-size:cover;
}
.profilen {
width: 100%;
text-align: left;
clear: both;
}
</style>
<div class="profilen">
<div class="profilbg">
<?php echo nl2br($uin->profilen); ?>
</div>
</div>

使用这段代码,如果内容太多,背景图像只会放大并变大。

最佳答案

您可以将此 CSS 规则用于背景图片:

.profilbg {
background: url(<?php echo $uin->backgroundimg; ?>) no-repeat #000 // Your bg color;
background-size: 100%;
}

这将使您的背景图像仅 100% 宽度,不包括高度,图像后背景颜色将自动出现。

关于javascript - Div 背景图片最大尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36129415/

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