前端总结之CSS篇

1. 盒模型

⻚⾯渲染时 dom 元素所采⽤的 布局模型。可通过 box-sizing 进⾏设置。根据计算宽⾼的区域可分为

content-box ( W3C 标准盒模型) border-box ( IE ) padding-box

margin-box (浏览器未实现)

2. BFC

块级格式化上下⽂,是⼀个独⽴的渲染区域,让处于 BFC 内部的元素与外部的元素相互隔离,使内外元素的定位不会相互影响。

IE下 Layout ,可通过 zoom:1 触发触发条件:

根元素

position: absolute/fixed display: inline-block / table

float

ovevflow !== visible

规则:

属于同⼀个 BFC 的两个相 Box 垂直排列

属于同⼀个 BFC 的两个相 Box  margin 会发⽣重叠

BFC 中⼦元素的  margin box 的左边 包含 (BFC)  border box 的左边相接触(⼦元素 absolute 除外)

BFC 的区域不会 float 的元素区域重叠计算 BFC 的⾼度时,浮动⼦元素也参与计算

⽂字层不会被浮动层覆盖,环绕于周围应⽤:

阻⽌ margin 重叠

可以包含浮动元素 —— 清除内部浮动(清除浮动的原理是两个 div 都位于同⼀个  BFC 区域之中)

⾃适应两栏布局

可以阻⽌元素被浮动元素覆盖

3.层叠上下⽂

元素提升为⼀个⽐较特殊的图层,在三维空间中 (z轴) ⾼出普通元素⼀等。

触发条件

根层叠上下⽂( html )

position

css3 性:

flex

transform

opacity

filter

will-change

webkit-overflow-scrolling

层叠等级:层叠上下⽂在z轴上的排序

在同⼀层叠上下⽂中,层叠等级才有意义

z-index 的优先级最⾼

4.居中布局

⽔平居中

⾏内元素: text-align: center : margin: 0 auto absolute + transform

flex + justify-content: center

垂直居中

line-height: height absolute + transform

flex + align-items: center table

⽔平垂直居中

absolute + transform

flex + justify-content + align-items

5. 选择器优先级

!important > > #id > .class > tag > * > > 认选择 从右往左

6. 去除浮动影响,防⽌⽗级⾼度塌陷

通过增加尾元素清除浮动

:after / <br> : clear: both

创建⽗级   BFC

⽗级设置⾼度

7.link  @import 的区别

link 功能较多,可以定义 RSS ,定义 Rel 等作⽤, @import 只能⽤于加 css

当解析 link 时,⻚⾯会同步加载所引的 css , @import 所引⽤的 css 会等到⻚

⾯加载完才被加载

@import 需要 IE5 以上才能使⽤

link 可以使⽤ js 动态引⼊ @import 不⾏

8. CSS预处理器(Sass/Less/Postcss)

CSS 预处理器的原理: 是将类  CSS 语⾔通过 Webpack 编译 转成浏览器可读的真正 CSS 。在这层编译之上,便可以赋予 CSS 更多更强⼤的功能,常

⽤功能:

嵌套

变量

循环语句

条件语句

⾃动前缀

单位转换

mixin 

9.CSS动画

transition: 过渡动画

transition-property :

transition-duration :

transition-timing-function : 曲线

transition-delay :

常⽤钩⼦: transitionend

animation / keyframes

 animation-name : 动画名称,对应 @keyframes

animation-duration :

animation-timing-function : 曲线

animation-delay :

animation-iteration-count :

infinite : 循环动画

animation-direction :

alternate : 反向播放

animation-fill-mode : 静⽌模式forwards : 停⽌时,保留最后⼀帧

backwards : 停⽌时,回到第⼀帧

both : 同时运 forwards / backwards

常⽤钩⼦: animationend

动画属性: 尽量使⽤动画属性进⾏动画,能拥有较好的性能表现

translate

scale

rotate

skew

opacity

color

猜你喜欢

转载自www.cnblogs.com/yongbin668/p/12194456.html