七、元素垂直水平居中的方案

2019-12-08  本文已影响0人  yuzhan550

1.无论是否知道宽高

a.包含块一定得是容器

b.position:absolute ,left:50%;top:50%,

c. transform:translate3d(-50%,-50%,0);

(abc是一个方案的三个步骤)

2. 已知宽高:

方案一:

position:absolute; lrtb=0; margin=auto
包含块的width = left+right+width+padding+margin
包含块的height = top+bottom+height+padding+margin

方案二:

a.包含块一定得是容器

b.position:absolute ,left:50%;top:50%,

c. marginT/L=-50%(自身)

3. 未知宽高:

flex

上一篇 下一篇

猜你喜欢

热点阅读