您的位置:首页 > 其它

关于网页居中的问题

2007-12-08 19:31 295 查看

我看到有些网页在IE里是居中的,可是到了Firefox里就靠左了,其实这个问题很简单,看下面这段代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>网页居中</title>

<style>

body

{

text-align:center;

}

div.window

{

border:#330066 solid 1px;

width:800px;

height:700px;

margin-left:auto;

margin-right:auto;

}

</style>

</head>

<body>

<div class="window"></div>

</body>

</html>

复制上面的代码,保存为index.html,用浏览器浏览下效果,可以看到窗口永远是居中的

原理是在你要居中的窗口(该例是window)的样式中添加margin-left:auto;margin-right:auto;让它左右空隙都自动,这样它就能自动居中对齐了。本文出自 “我的空间show” 博客,请务必保留此出处http://csprogrammer.blog.51cto.com/212533/54212
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: