HTML 正文背景图片未覆盖所有页面

标签 html css

我正在尝试将背景图片设置为整个 html 页面,但我每次都失败了。它没有拉伸(stretch)。这是我的 css 和 html 代码:

CSS 代码:

body {
    background-image:url(body_background.png);
    background-repeat: no-repeat;
    background-size: 100% 100%;
    width:1200px;
    margin:0 auto;
}

#main_container_div {
    padding: 0px;
    width: 1000px;
    margin-top: 30px;
    margin-left: 150px;
}

#div2 {
    float: left;
    width: 250px;
    height: 600px;
    margin-top: 0px;
    margin-right: 0px;
    background-repeat: no-repeat;
}
#div3 {
    position: relative;
    float: left;
    width: 750px;
    height: 500px;
    margin-top: 50px;
    overflow: hidden;
}

HTML 正文:

<body>    
    <div id="main_container_div">
        <div id="div3">
        </div>
        <div id="div2">
        </div>
    </div>
</body>

您可以尝试使用尺寸为 1366x768 的图像。我也在 1366x768 分辨率上尝试这个。请注意,这个问题在这个或更高的分辨率下是可见的。感谢您的帮助..

最佳答案

尝试 background-size: cover 在你的 CSS 中

background-size:cover;

关于HTML 正文背景图片未覆盖所有页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14705710/

相关文章:

javascript - 获取元素的父id

html - 在 HTML Swift 中编码字符串

javascript - jquery 脚本在桌面上工作,但在 iphone 上滞后

javascript - Jquery 不会隐藏元素

html - 当内容肯定离开页面时,为什么这个滚动条会变灰?

html - RoR Agile Web Dev 4 CSS 未加载

javascript - Accordion 在 IE6 中乱七八糟

c++ - 如何使用 C++ 从网页中获取文本?

javascript - 允许触摸滚动以防溢出隐藏

javascript - 将 html block 写成字符串