ie7怎么对margin:0px auto不管用!

huayiluo 2008-03-29 02:37:23
求一个管用的。
...全文
1015 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
nickchen119 2010-03-05
  • 打赏
  • 举报
回复
html文档最顶部少了下面这样一行代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
AsiaHT 2008-10-10
  • 打赏
  • 举报
回复
<!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>Hello,World!</title>
<style type="text/css">
#header{
background : #cccccc ;
border : 2px solid #333333 ;
width : 100% ;
height : 300px ;
margin : 0px auto ;
}
</style>

</head>

<body>
<div id="header">
<h1>Title</h1>
<ul>Navigator</ul>
</div>
<div id="center">
<div id="left">Left</div>
<div id="right">Right</div>
</div>
<div id="footer">Foot</div>
</body>
</html>
注:该代码再IE7.0版本上已经调试通过,关键是前面的红色部分。
zerocoin 2008-03-31
  • 打赏
  • 举报
回复
这个居中的使用条件是先指定外容器的宽度, 如:100%;
然后在里面有要居中的容器设置这个样式就可以实现居中效果了.
<div style="width:100%">
<div style="margin: 0px auto">
</div>
</div>
away8_girl 2008-03-31
  • 打赏
  • 举报
回复
分开写嘛 margin-left:auto;margin-right:auto 基本的浏览器都适用了
Atai-Lu 2008-03-31
  • 打赏
  • 举报
回复

<!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 type="text/css">
<!--
body{margin-left:0;margin-top:10px;margin-right:0;margin-bottom:10px;}
#div{margin-left:auto;margin-right:auto;width:76%;}
#pbody{border:#88cee9 1px solid;padding:15px;}
-->
</style></head>
<body>
<div id="div">
<div id="pbody">
这个试试
</div>
</div>
</body>
</html>

是不是dtd引用不正确???
<!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">
这个
liuqinqin 2008-03-29
  • 打赏
  • 举报
回复
没有设置宽度吧;
魔豆爸 2008-03-29
  • 打赏
  • 举报
回复
ie下有个bug,ie7仍然没有解决。所以要用到一个hack
1,先让整个body内容居中
body {
text-align: center;
min-width: 760px;
}
2,利用自动空白边居中该容器,再让内容向左靠齐,宽度自己可以调
#wrapper {
width: 720px;
margin: 0 auto;
text-align: left;
}
liefdiy 2008-03-29
  • 打赏
  • 举报
回复
你是想设置居中吧

#name {
position:absolute;
left:50%;
width:760px;
margin-left:-380;//值为负的容器宽度的一半
}

如此即可,任何浏览器里都能用。

61,129

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧