- 行内元素
.parent {
height: 高度;
}
.son {
line-height: 高度;
}
- table
.parent {
display: table;
}
.son {
display: table-cell;
vertical-align: middle;
}
- flex
.parent {
display: flex;
align-items: center;
}
- 绝对定位定高
.son {
position: absolute;
top: 50%;
height: 高度;
margin-top: -0.5高度;
}
- 绝对定位不定高
.son {
position: absolute;
top: 50%;
transform: translate( 0, -50%);
}
- top/bottom: 0;
.son {
position: absolute;
top: 0;
bottom: 0;
margin: auto 0;
}
1.如需转载本站原创文章,请务必注明文章出处并附上链接,非常感谢。
2.本站用于记录个人 工作、学习、生活,非商业网站,更多信息请 点击这里
上一篇: 圣杯布局与双飞翼布局
下一篇: javascript判断数据类型