<分区>
<分区>
<!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=utf-8" />
<title>Untitled Document</title>
<style>
#a
{
background:#33F;
width:1000px;
height:1000px;
}
#b
{
width:500px;
height:500px;
background:#F00;
}
#c
{
margin-top:50px;
height:200px;
width:200px;
background:#FF0;
}
</style>
</head>
<body>
<div id="a">
<div id="b">
<div id="c">
</div>
</div>
</div>
</body>
</html>
为什么 div#c 从浏览器顶部开始边缘化而不是远离 div#b。
最佳答案
CSS has a concept called margin collapse .
Two margins are adjoining if and only if:
...
- both belong to vertically-adjacent box edges, i.e. form one of the following pairs:
- top margin of a box and top margin of its first in-flow child
关于html - CSS 边距不起作用。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14325788/