日期:2014-05-17  浏览次数:20573 次

让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 xml(标准化越来越近了)ns="http://www.w3.org/1999/xhtml">
<head>
<title>
做一个测试--WEB开发网
</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">
WEB开发网 测试页面
</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浏览器里的显示还是居左的, 在火狐和谷歌浏览器时的显示是正确的, 加了这句后, 所有的浏览器时显示都是正

转自:http://www.cncms.com.cn/css/14556.htm