不用table,两种div+css页面元素居中方法

来源:互联网 发布:中国保险网络教育大学 编辑:程序博客网 时间:2024/05/16 12:11

第一种:绝对定位法:

<style>html { height: 100%; }</style>
<body style="height: 100%; text-align: center; position: relative; "><div style="position: absolute; left: 50%; top: 50%; width: 480px; height: 220px; margin-left: -240px; margin-top: -110px; "><img src="images/logo.gif" width="480" height="189" /><br /><br /><a href="home.php">中文版</a>  |   <a href="English.php">English</a></div>

第二种:空白DIV法:

<body style="height: 100%;text-align: center;">
<div style="height: 50%; margin-top: -110px; ></div><div style="width: 480px; height: 220px;  margin: 0 auto; "><img src="images/logo.gif" width="480" height="189" /><br /><br /><a href="home.php">中文版</a>  |   <a href="English.php">English</a></div>