<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
div{
width: 100px;
height: 100px;
}
#d1{
background-color: red;
/* margin: 100px; */
margin-bottom: 100px;
}
#d2{
background-color: blue;
/* margin: 200px; */
margin-top: 200px;
}
main{
width: 500px;
height: 500px;
background-color: green;
/* transparent 透明 */
/* border: solid 1px transparent; */
/* padding: 1px; */
/* overflow: hidden; */
position: relative;
}
#d3{
background-color: yellow;
margin-top: 100px;
/* float: left; */
position: absolute;
}
</style>
</head>
<body>
<!-- 外边距合并(塌陷) -->
<!-- 1.兄弟关系的合并 -->
<!-- 取大值 -->
<div id="d1"></div>
<div id="d2"></div>
<!-- 2.父子关系的合并 -->
<!--
1.为父元素添加border (常用)
2.为父元素添加padding
3.为父元素添加overflow: hidden
4.为子元素添加float
5.为父元素添加 position
-->
<main>
<div id="d3"></div>
</main>
<div style="background-color: teal;">12121212121212121</div>
</body>
</html>
外边距合并问题
最新推荐文章于 2022-02-26 20:30:01 发布