设置不定宽高的div垂直水平居中

1、使用table-cell
父级设置: display: table-cell; text-align: center; vertical-align: middle;
子级设置: display: inline-block; vertical-align: middle;
2、使用transform
父级设置:display: relative;
子级设置:transform: translate(-50%,-50%); position: absolute; top: 50%; left: 50%;
3、使用flex
父级设置:display: flex; justify-content: center; align-items: center;

猜你喜欢

转载自www.cnblogs.com/xiaodiao/p/12307524.html