首页 > 试题广场 >

垂直居中

1.对于行内文本,使用line-height设置成父级的高度
2.绝对定位加上top: 0;left: 0;bottom: 0;right: 0;再使用margin: auto 0;
3.利用平移。即left:50%,;top:50%;transform:translate(-50%,-50%)
4.父元素设置成display:table,子元素设置成单元格,即display:table-cell
5.利用弹性布局display:flex,设置align-item:center;justify-content:center;
发表于 2023-10-11 15:52:19 回复(0)