Collapsing margins

例子请用Firefox, Opera, Safari,google查看

before

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" media="screen">
body { margin:0;padding:0;font:13px/14px arial;}
.context {float:left;}
#outside { margin-bottom: 100px;}
</style>
</head>
<body>
<div id="outside">
<div class="context">
父容器里设置margin-bottom:100px....是不是觉得象margin:100px auto 100px auto;
</div>
</div>
</body>
</html>

after

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>HTML document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" media="screen">
body { margin:0;padding:0;font:13px/14px arial;}
.context {float:left;}
#outside { margin-bottom: 100px;padding:1px;/*height:1px;*/ /*border:1px solid #000;*/}
</style>
</head>
<body>
<div id="outside">
<div class="context">
父容器里设置margin-bottom:100px....是不是觉得象margin:100px auto 100px auto;
</div>
</div>
</body>
</html>
 
可以利用height, border以及padding。来解决这个烦人的问题

你可能感兴趣的:(margin)