html - 如何使 div 的背景覆盖整个页面

标签 html css

我现在正在处理一个网页,我需要一个 div 背景来覆盖整个页面(100% 宽度)。

我的问题是 div 的内容应该在一个 950px 的 div 中居中,而带有背景的 div 应该放在一个宽度为 950px 的 div 中。

我想不出我应该如何让它工作。有人可以帮帮我吗。

最佳答案

我不确定你在找什么。是这样的吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <style>
            .outerDiv { width:100%; background:#DEDEDE; }
            .innerDiv { width:950px; margin:0 auto; border:solid 2px #000000; }
        </style>
    </head>
    <body>
        <div class="outerDiv">
            <div class="innerDiv">
                This is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test, this is a test.
            </div>
        </div>
    </body>
</html>

关于html - 如何使 div 的背景覆盖整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3595579/

相关文章:

html - 如何使用 CSS 使图像居中

CSS2 DIV 演示问题

Jquery点击显示和隐藏

css - Bootstrap3.3.7.min.css 破坏了禁用的按钮

javascript - onmouseover/onmouseout 与 JQuery 冲突。悬停在 chrome 上?

html - 需要能够使用适用于所有按钮的代码来定位单个按钮

html - 样式单选按钮只允许选择一个按钮

javascript - jQuery如何在到达容器末尾时捕捉到容器

Javascript 提示对话框自定义输入

html - :active css 上不需要的转换