css+div使网页居中显示

来源:互联网 发布:有什么配音软件 编辑:程序博客网 时间:2024/04/27 15:13

css+div使网页居中显示

*/-->

css+div使网页居中显示

Table of Contents

  • 1 center inline element
  • 2 hack
  • 3 use fixed number of width to center the page

1 center inline element

to center inline elements within a block element, use text-align: center;

2 hack

<body><div style="width:400px; background-color:green;height:300px; position:relative;left:50%;margin-left:-200px;"></div></body>

第三种方法,是通过left样式,让div左边正好还正中。但我们需要的是div的中心在正中,那么就再加一个margin-left的属性,值赋成div宽度的一半,当前div就真的居中了,挺巧妙的。

3 use fixed number of width to center the page

<style> background:#00f;position :absolute;top:50%;left:50%;width:300px;height:150px;margin-Top:-75px;margin-Left:-150px;

}</style><div id="alert"> DIV 标签对齐方式,不管什么样的浏览器,不管多大的分辨率,都在正常居中显示</div>

Author: <zfreay@ZFREAY-PC>

Date: 2011-06-28 00:02:14

HTML generated by org-mode 6.33x in emacs 23

原创粉丝点击