10.html的外边距,内边距和边框

1.首先,我们先了解下外边距
div{
width: 100px;
height: 100px;
background-color: pink;
}
#d1{
/*单独某一个方向赋值*/
margin-left: 50px;
margin-top: 50px;
margin-bottom: 30px;
margin-right: 50px;
margin: 50px;/*四个方向赋值*/
margin: 50px 100px;/*上下50 左右100*/
margin: 10px 20px 30px 40px;/*上右下左顺时针赋值*/
}
#d2{
/*外边距塌陷问题:上下相邻的兄弟元素彼此添加外边距取最大值*/
margin-top: 50px;
}
/*行内元素上下外边距无效*/
#s1{margin-right: 50px}
#s2{margin-left: 50px}/*左右相邻彼此添加外边距两者相加*/
#big{
width: 200px;height: 200px;background-color: red;
overflow: hidden;/*解决粘连问题*/
}
#big>div{
width: 50px;height: 50px;
background-color: blue;
margin-left:50px;
/*外边距塌陷问题导致父子元素的上外边距取最大值出现粘连的问题*/
margin-top: 50px;
}
span1span2
2.内边距和边框
body{
margin: 0;
}
/**{margin: 0}*/
h1,p,ul{margin: 0}
ul{padding: 0}
#d1 {
width: 400px;
height: 200px;
border: 10px inset red;
/* border-bottom: 10px solid red;
border-right: 10px solid red;*/
/*设置圆角*/
border-radius: 200px;
}
#d2 {
width: 100px;
height: 100px;
border: 1px solid blue;
/*给元素添加内边距 默认会影响元素的宽高*/
padding-left: 50px;
padding-top: 50px;
/*添加这个样式后 内边距和边框则不再影响宽高*/
box-sizing: border-box;
}
这是h1
这是p标签
- aaa
- bbb
- ccc
内边距