#面试题 #css
- 定高:margin,position + margin(负值)
- 不定高:position + transform,flex,IFC + vertical-align:middle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| .center { height: 100px; margin: 50px 0; }
.center { height: 100px; position: absolute; top: 50%; margin-top: -25px; }
.center { position: absolute; top: 50%; transform: translateY(-50%); }
.wrap { display: flex; align-items: center; } .center { width: 100%; }
.wrap::before { content: ''; height: 100%; display: inline-block; vertical-align: middle; } .wrap { text-align: center; } .center { display: inline-block; vertical-align: middle; }
|
https://juejin.cn/post/6844903982960214029