webveuje/csspress/demo/margin3.html
2021-01-18 18:11:23 +08:00

47 lines
1.1 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
width:600px;
height:300px;
background: gold;
/* padding-top:50px;
border-top: 1px solid white;
overflow: hidden; */
}
.box1{
width:50px;
height: 50px;
background:red;
/* margin-top: 50px; */
}
.box2{
width:50px;
height:50px;
background: blue;
margin-top: 100px;
}
.box3{
background:pink;
}
</style>
</head>
<body>
<div class="box">
<div class="box1">中国</div>
</div>
<p>总结:当只给中国加上边距时,他外层的父元素也会跟着往下移动 ,这种现象叫父子级的边距合并
解决方式padding-top:50px;
border-top: 1px solid white;
overflow: hidden
</p>
</body>
</html>