1、浏览器默认都会有一些内外边距,并且值还不一样,所以,实际开发都会清空内外边距
* {
margin: 0;
padding: 0;
}
2、能够使块元素居中对齐的方案。1:设置块元素的宽度 2:设置margin:0 auto样式。其中上下边距可以不是0。
900px;
height: 200px;
background-color: pink;
margin: 100px auto;
text-align: center;
}
3、解决父元素和子元素外边距塌陷得到问题。
<style>
.father {
400px;
height: 400px;
background-color: purple;
margin-top: 50px;
/* 解决父元素外边距塌陷的问题 又三种解决方案 */
/* 解决方案1:为父元素添加边框 */
/* border: 1px solid red; */
/* 解决方案2:为父元素添加内边距 */
/* padding-top: 1px; */
/* 解决方案3:为父元素添加overflow:hidden */
overflow: hidden;
}
.son {
200px;
height: 200px;
background-color: pink;
margin-top: 100px;
}
</style>
<div class="father">
<div class="son"></div>
</div>
4、