Html 如何在整个页面上创建div跨度的背景
我现在正在处理一个网页,我需要一个div的背景来覆盖整个页面(100%宽度) 我的问题是div的内容应该集中在一个950px的div中,这个div是集中的,而带有背景的div被放置在一个950px宽度的div中Html 如何在整个页面上创建div跨度的背景,html,css,Html,Css,我现在正在处理一个网页,我需要一个div的背景来覆盖整个页面(100%宽度) 我的问题是div的内容应该集中在一个950px的div中,这个div是集中的,而带有背景的div被放置在一个950px宽度的div中 我想不出我该如何让它工作。谁能帮帮我吗。我不知道你在找什么。是这样的吗 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tr
我想不出我该如何让它工作。谁能帮帮我吗。我不知道你在找什么。是这样的吗
<!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>
.outerDiv{宽度:100%;背景:#DEDEDE;}
.innerDiv{宽度:950px;边距:0自动;边框:实心2px#000000;}
这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试,这是测试。
您可以在中使用这些技术之一来获得100%宽度的背景图像。然后,要使内容分区居中,您只需要以下内容:
<div style="margin: 0 auto; width: 950px;">
Your content goes right m'ere
</div>
你的内容就在这里
上面所做的是创建一个950px宽的div,顶部和底部的边距为0px
,左侧和右侧的边距为auto
。这将根据模型将块级图元居中放置在其父图元中:
如果“左边距”和
“右边距”为“自动”,其使用
价值观是平等的。这是横向的
使元素相对于
包含块的边
我想我不明白。你能不能先有一个100%宽的div,然后再在里面嵌套一个950px宽且居中的div?没错,“margin:0auto;”是一个更好的方法。我已经相应地修改了我的答案。没问题。需要记住的是,元素应该有一个定义的宽度,但它在IE5中不起作用(为此,您需要将它放在带有
text align:center
的父容器中)。根据Pat的说明,我已将outerDiv中的“text align:center;”替换为innerDiv中的“margin:0 auto;”。