webveuje/csspress/demo/margin3.html

47 lines
1.1 KiB
HTML
Raw Normal View History

2021-01-18 18:11:23 +08:00
<!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>