让div+css的div居中, 而里面的文字不居中的做法

来源:岁月联盟 编辑:zhu 时间:2008-12-08
让div+css的div居中, 而里面的文字不居中的做法内容简介:让div+css的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 让div+css的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>
<title>
做一个测试
</title>
<style type="text/css" rel="stylesheet">
body{
margin:0px;
}
#countainer{
margin:auto;
width:600px;
height:100%;
background-color:#cccccc;
}
</style>
</head>
<body>
<div id="countainer">
中国
</div>
</body>
</html>


事实上, 这里的最关键的一个点在: countainer类的属性里的: margin:auto; 这个值!

刚才测试时, 发现里的<!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">

也是很重要的, 如果没有这句在IE浏览器里的显示还是居左的, 在火狐和谷歌浏览器时的显示是正确的, 加了这句后, 所有的浏览器时显示都是正

图片内容