1.ie 盒模型算上 border、padding 及自身(不算 margin),标准的只算上自身窗体的大小 css 设置方法如下
/* 标准模型 */
box-sizing:content-box;
/*IE模型*/
box-sizing:border-box;
2.margin、border、padding、content 由外到里 3.几种获得宽高的方式
4.拓展 各种获得宽高的方式
5.边距重叠解决方案(BFC)BFC原理
<section class="top">
<h1>上</h1>
这块margin-bottom:30px;
</section>
<!-- 给下面这个块添加一个父元素,在父元素上创建bfc -->
<div>
<section class="bottom">
<h1>下</h1>
这块margin-top:50px;
</section>
</div>
水平方向上
针对 inline, 内联块inline-block, 内联表inline-table, inline-flex元素及img,span,button等元素
.text_div{
text-align:center;
}
不定宽块状元素居中
.text_div{
margin:0 auto;//且需要设置父级宽度
}
通过给父元素设置 float,然后给父元素设置 position:relative 和 left:50%,子元素设置 position:relative 和 left: -50% 来实现水平居中。
.wrap{
float:left;
position:relative;
left:50%;
clear:both;
}
.wrap-center{
left:-50%;
}
垂直居中
单行内联(inline-)元素垂直居中
通过设置内联元素的高度(height)和行高(line-height)相等,从而使元素垂直居中。
.text_div{
height: 120px;
line-height: 120px;
}
利用表布局
.father {
display: table;
}
.children {
display: table-cell;
vertical-align: middle;
text-align: center;
}
flex布局
.center-flex {
display: flex;
flex-direction: column;//上下排列
justify-content: center;
}
绝对布局方式
已知高度
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
height: 100px;
margin-top: -50px;
}
未知高度
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
垂直水平居中根据上方结合
flex方式
.parent {
display: flex;
justify-content: center;
align-items: center;
}
grid方式
.parent {
height: 140px;
display: grid;
}
.child {
margin: auto;
}
不清楚浮动会发生高度塌陷:浮动元素父元素高度自适应(父元素不写高度时,子元素写了浮动后,父元素会发生高度塌陷)
.float_div:after{
content:".";
clear:both;
display:block;
height:0;
overflow:hidden;
visibility:hidden;
}
.float_div{
zoom:1
}
思路:
#item {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 50px solid transparent;
border-bottom: 50px solid blue;
background: white;
}

