网页中怎么让层居中?

来源:百度知道 编辑:UC知道 时间:2024/05/29 00:48:01
请高手们帮忙看一下为什么我这样写的代码不能使层居中显示呢?但是在设计视图中可以看到居中效果,在浏览器中就看不到居中效果,这是为什么呢?

<body>
<div id="container" style="text-align:center; width:1300px; border:solid 1px red;">
<div id="mm" style="background-color:#32556b; width:800px; height:600px;">fdsfdasda
</div>
</div>
</body>

在你想要居中的对应的div的css里写上margin:0 auto;
一般在div的标签里写align="center"起不到作用
还有就是别看设计视图里的效果,那个不可靠,你得通过浏览器来看

<body>这里加个(不是很规范但很有效)<center>

还有,把1300px改成900,别超过你屏幕的宽度。

margin:0 auto;

<div id="mm" style="background-color:#32556b; width:800px; height:600px; margin:0 auto;">fdsfdasda
</div>