html+css做网页时,如何让整张网页居中显示

html-css026

html+css做网页时,如何让整张网页居中显示,第1张

使用CSS 语法要设定一个div 水平置中,是很常见到的需求,最多人使用margin: 0 auto这个方法就可以达成。但是,如果要让一个div 同时间做到在网页上水平置中还要垂直置中,也就是CSS 上下左右置中这就有点麻烦了,不太容易喔!

利用table中内容在单元格中默认垂直居中的特性。

2.利用css3中的transform属性

3.利用margin属性

4.利用利用position属性把left,top,right,bottom四个的值设为0,再用margin:auto

最好把你的代码改写了一下,并实现居中效果

效果图

可从两个方面来确保在各种浏览器中全局居中:

<style type="text/css">

body{text-align:center}/*针对老式浏览器*/

#wrapper{margin:0 autowidth:1000px}/*要指定宽度*/

</style>

<body>

<div id="wrapper">页面内容</div>

</body>

text-align: center 只能用于行内元素的水平居中,用在块级元素或容器中是无效的

试试这样:

<div class="metro-layout horizontal" style="margin: 0 auto">