001 让一个元素水平垂直居中,到底有多少种方案?
CoderBin 1/27/2021 CSS布局
# 水平居中
对于
行内元素: text-align: center;对于确定宽度的块级元素:
width和margin实现。margin: 0 auto;
绝对定位和margin-left: -width/2, 前提是父元素position: relative
- 对于宽度未知的块级元素
对于行内元素: text-align: center;
对于确定宽度的块级元素:
width和margin实现。margin: 0 auto;
绝对定位和margin-left: -width/2, 前提是父元素position: relative