关于CSS的一个问题。magin:0px auto;不能显示居中效果?

来源:百度知道 编辑:UC知道 时间:2024/06/24 08:07:01
我看的是李超编著的《CSS网站布局实录》这本书。
在第64页的一列宽度自适应中。有个例子。
代码如下:

<html>
<head>
<title></title>
<sytle>
#layout{
background-color:#cccccc;
border:2px solid #333333;
width:300px;
height:300px;
margin:0px auto;
}
</style>
<body>
<div id="layout"></div>
</body>
</html>

据讲解。margin:0px auto;这段代码是将div的左右边距设为相同,从而达到居中的效果。可是我测试的时候没有居中。不知道是哪里错了。
请达人指教。必有重谢!

百度知道里竟然没有网页制作的分类。我只好放到JAVA里了。我想学JAVA的都会CSS吧。。
@@@@@@@@@@@@@@@@@@@@@@@

就是说doctype和meta必须指定才行吧??
因为是直接输入代码,所以就懒得写了.

margin的auto属性在css1里就有定义……ie4、ns4开始就支持了……

楼主的style标签打错了,不是sytle。另外最主要的是你没有!DOCTYPE字段申明,所以才导致这种现象,把下面代码复制到html文件中试试:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</head>
<body>

<style type="text/css">
#layout{
background-color:#cccccc;
border:2px solid #333333;
width:300px;
height:300px;
margin:auto;
}
</style>
<body>
<div id="layout"></div>