Q2:页面元素的水平垂直居中 flex12345678910111213.parent { width: 300px; height: 300px; display: flex; justify-content: center; align-item: center; background: yellow;}.child { width: 100px; height: 100px; background: red;} 相对定位 + transform123456789101112.parent { position: relative;}.child { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 100px; height: 100px;} 相对定位 + margin: auto1234567891011121314.parent { position: relative;}.child { position: absolute; top: 0; bottom: 0; left: 0; right: 0; margin: auto; width: 100px; height: 100px;} 相对定位 + margin 的负值12345678910111213.parent { position: relative;}.child { position: absolute; top: 50%; left: 50%; margin-top: -50px; margin-left: -50px; width: 100px; height: 100px;} table-cell123456789.parent { display: table-cell; vertical-align: middle; text-align: center;}.child { display: inline-block;} grid12345678.parent { display: grid;}.child { align-self: center; justify-self: center;}