#mainBody{
width: 960px;
margin-left:auto;
margin-right:auto;
}
IE中必须在body里面加上"text-align:center
"!
代码如下:
<!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>
<title>
DIV在IE和FF中的居中处理
</title>
<style type="text/css" rel="stylesheet">
body{
margin:0px;
}
#main{
margin:auto;
width:600px;
height:100%;
background-color:#cccccc;
}
</style>
</head>
<body>
<div id="main">
DIV在IE和FF中的居中处理
</div>
</body>
</html>
本文介绍了一种使DIV元素在Internet Explorer (IE) 和 Firefox 中实现居中的方法。通过设置CSS属性,如margin:auto和特定宽度,可以确保在不同浏览器中DIV元素保持居中显示。此外,在IE中还需要额外设置body的text-align:center来达到效果。
150

被折叠的 条评论
为什么被折叠?



