求教css高手,下面这个怪异的问题

Even713 2010-01-22 11:39:50
code 1:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<meta http-equiv="Content-Type" content="text/html;" charset="gb2312"></meta>
<head>
</head>
<style>
#top_outer{
width:100%;
height:20px;
background:#EDF2F6;
}

#page_outer{
width:100%;
height:400px;
background:#EDF2F6;
border:1px solid red;
}

#mainContent{
border:1px solid red;
margin-top:50px;
margin-left:50%;
width:50%;
height:200px;/**/
}
</style>
<body>
<div id="top_outer">
</div>

<div id="page_outer">
<div id="mainContent">
</div>
</div>
</body>
</html>


code2:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<meta http-equiv="Content-Type" content="text/html;" charset="gb2312"></meta>
<head>
<title>登录</title>
</head>
<style>
#top_outer{
width:100%;
height:20px;
background:#EDF2F6;
}

#page_outer{
width:100%;
height:400px;
background:#EDF2F6;
}

#mainContent{
border:1px solid red;
margin-top:50px;
margin-left:50%;
width:50%;
height:200px;/**/
}
</style>
<body>
<div id="top_outer">
</div>

<div id="page_outer">
<div id="mainContent">
</div>
</div>
</body>
</html>


麻烦运行一下代码
这两段代码的差别在 #page_outer 上,仅仅多了一句 border 1px的修饰,但造成的效果却大相径庭。
maincontent的margin-top应该是相对于父容器的吧?为什么在code2中会使得top_outer 和 page_outer当中有间隙呢?
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ddcatlee 2010-01-22
  • 打赏
  • 举报
回复
google 垂直边距压缩(或 重叠)
hookee 2010-01-22
  • 打赏
  • 举报
回复
firebug下可以看到,位置实际上是对的,只是没有字符的话,底色没有显示出来
hookee 2010-01-22
  • 打赏
  • 举报
回复
FF下有间隙,加一个  就可以了

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html>
<meta http-equiv="Content-Type" content="text/html;" charset="gb2312"></meta>
<head>
<title>登录</title>
</head>
<style>
#top_outer{
width:100%;
height:20px;
background:#0F0;
}

#page_outer{
width:100%;
height:400px;
background:#EDF2F6;
}

#mainContent{
border:1px solid red;
margin:50px 0 0 50%;
height:200px;
}
</style>
<body>
<div id="top_outer">
</div>

<div id="page_outer"> 
<div id="mainContent">
</div>
</div>
</body>
</html>
Even713 2010-01-22
  • 打赏
  • 举报
回复
谢谢解答

我用的是ie8与ff
加上body{font-size:0px}效果一样

我刚做了测试,在code2中的page_outer这个容器中加些文字,这个间隙也可以没有。

有点费解
hookee 2010-01-22
  • 打赏
  • 举报
回复
光上述代码 测试下来没发现top_outer 和 page_outer之间有间隙
加上body{font-size:0px}试试看,
另外,是不是多了border 1px后引起page_outer的总长度的变化造成的?
ck11926375 2010-01-22
  • 打赏
  • 举报
回复
IE6 显示正常
FF 显示有白色的

CSS样式表里尽量少用MARGIN

你把margin-top:50px;这句删掉 两个都正常了!

61,115

社区成员

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

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