忠告:能不写 height 就千万别写 height。
- 如果 .parent 的 height 不写,你只需要 padding: 10px 0; 就能将 .child 垂直居中;
- 如果 .parent 的 height 写死了,就很难把 .child 居中,以下是垂直居中的方法。
一、table自带
二、div 装成 table
三、通过相对定位和绝对定位来实现
四、flex布局
justify-content: center;
3align-items: center;
justify-content: center;
3align-items: center;