|
现在流行DIV+CSS
唉……
在下不是一个追求流行的人,事实上考虑到低版本浏览器兼容,Table+CSS的兼容性更好……
不过与时俱进也是必须的
页面居中是很多网站最基本的需求
DIV+CSS的情况下,IE很简单:
<STYLE> /* 总体布局 */ body { text-align:center;margin:0px; }
</STYLE>
但是这个代码在FF下是没有效果的,需要增加:
<STYLE>
#top_navigation { width:980px ; background-repeat:no-repeat ; margin-left:auto ; margin-right:auto ; overflow:hidden }
</STYLE>
然后把<body>...</body>之间的所有内容放在一个DIV中间
即:
<div id="top_navigation">
</div>
示例代码:
|
<html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>新建网页 1</title> <STYLE> /* 总体布局 */ body { text-align:center;margin:0px; }
#top_navigation { width:980px ; background-repeat:no-repeat ; margin-left:auto ; margin-right:auto ; overflow:hidden }
</STYLE> </head>
<body> <div id="top_navigation"> <table border="0" cellpadding="0" style="border-collapse: collapse" width="980" id="table1"> <tr> <td><img border="0" src="haha168_1024_blue.gif" width="980" height="1200"></td> </tr> </table> </div> </body>
</html> | |