前言
继续css小知识点
正文
1. 居中布局
-
水平居中
1.行内元素: text-align: center
2。块级元素: margin: 0 auto
3.absolute + transform
4.flex + justify-content: center -
垂直居中
1.line-height: height
2.absolute + transform
3…flex + align-items: center
4.table -
水平垂直居中
1.absolute + transform
2.flex + justify-content + align-items
2.选择器优先级
!important > 行内样式 > #id > .class > tag > * > 继承 > 默认
选择器 从右往左 解析
3.去除浮动影响,防止父级高度塌陷
1.通过增加尾元素清除浮动
:after
: clear: both
2.创建父级 BFC
3.父级设置高度
例子
.container{
border: 1px solid #ccc
}
.box1{
width: 200px;
height: 200px;
background: blue;
}
.box2{