我想显示一张图片作为我网站的背景,所以我使用以下代码
HTML:
<div>
<img src="images/background.jpg" id="bg" alt="background_image" />
</div>
CSS:
#bg {
width: 100%;
height: 75%;
position: absolute;
z-index: -5000;
}
我想知道如何限制背景的大小,因为我不希望它拉伸(stretch)超过 2000 像素。
谢谢
最佳答案
只需在您的 CSS 中包含 max-width。
#bg {
width: 100%;
max-width: 2000px;
height: 75%;
position: absolute;
z-index: -5000;
}
关于html - 全屏背景html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14721136/