html - 全屏背景html

标签 html css web background background-image

我想显示一张图片作为我网站的背景,所以我使用以下代码

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/

相关文章:

Javascript - 删除输入字段中的光标位置

javascript - 覆盖 console.log 时如何显示 Promise 对象的状态和值

javascript - 点击特定类触发打开模态事件

java - 将 Android Web 应用程序部署为 .JAR 的框架

css - Webkit CSS 来控制输入 [type=color] 中颜色周围的框?

html - CSS 在 Firefox 和 Chrome 中提供不同的布局

html - 使用 CSS 创建光泽光效果

css - 如何在列表旁边 float div(里面有两个居中的文本)?

python - 带有管理小部件的 Django ModelForm

html - 使用 <nav> 和 <li> <a> 还是只使用 <nav> <a> 更好?