让一个div居中的几种方法
方法一:
.table {display: table; width: 100%;}
.father {display: table-cell; vertical-align: middle;}
.son {margin: auto;}
方法二:
.father {line-height: 500px; text-align: center; font-size: 0;}
.son {display: inline-block;}
方法三:
.father {position: relative;}
.son { position: absolute;bottom:50%;left: 50%;margin-left: -50px; margin-bottom: -50px;}
方法四:
.father {position: relative;}
.son {position: absolute; top: 0; bottom:0; left: 0; right: 0; margin: auto;}
方法五:
.father{display: flex}
.son{margin:auto;}
方法六:
.father{position: relative;}
.son{position: relative;top:50%;left: 50%;margin-top: -75px;margin-left: -75px;}
以上方法来自网络。

浙公网安备 33010602011771号