.father { display: flex; justify-content: center; align-items: center; }
這種方式兼容性很差佈局
.son { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
IE9如下不支持transform屬性flex
.father { display: table; } .son { display: table-cell; vertical-align: middle; text-align: center; }
.father { text-align: center; } .father::before { content: ''; display: inline-block; height: 100%; vertical-align: middle; } .son { display: inline-block; }