在水平方向上居中 div { width: 450px; height: 150px; color: #fff; background-color: red; text-align: center; }
水平垂直居中 水平垂直居中 水平垂直居中 水平垂直居中 水平垂直居中 .parent { width: 400px; height: 200px; border: 1px solid #f00; display: table-cell; text-align: center; vertical-align: middle; }
不确定高度的文本在竖直方向上居中 div { width: 150px; color: #fff; background-color: red; padding-top: 30px; padding-bottom: 30px; }
使用弹性盒子布局 让文本水平垂直居中 .parent-box { width: 400px; height: 150px; display: flex; justify-content: center; /* 让子元素水平居中 */ align-items: center; /* 让子元素垂直居中 */ border: 1px solid #999; } .child-box { background-color: #fe5454; color: #fff; }
上一个:eslint在vue中如何使用