我现在正在处理一个网页,我需要一个 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/