1.—元素绝对定位,外边距自适应
html
1 | <div class="father"> |
css
1 | .father { |
2.—元素绝对定位,外边距取负值
html
1 | <div class="father"> |
css
1 | .father { |
这里有个问题,为什么采取margin-left,margin-top,
待解决:margin-right,margin-bottom,自己试了下,没有效果.
3.—元素绝对定位,平移自身
html
1 | <div class="father"> |
css
1 | .father { |
4.—table布局
display:table:此元素会作为一个表格单元格显示(类似 td 和 th)
html
1 | <div class="father"> |
css
1 | .father { |
5.—flex布局
html
1 | <div class="father"> |
css
1 | .father { |
6.—grid布局
html
1 | <div class="father"> |
css
1 | .father { |
小结
行内元素:
- 水平居中:text-align:center
- 垂直居中: 设置height=line-height
块级元素
- 无脑flex布局