弹性盒:
.container { display: flex; justify-content: center; align-items: center; height: 300px; }登录后复制
网格
.container { display: grid; place-items: center; height: 300px; }登录后复制
弹性保证金
.container { display: flex; height: 300px; } .centered-div { margin: auto; }登录后复制
绝对定位
.container { position: relative; height: 300px; } .centered-div { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }登录后复制
自动保证金
.container { height: 300px; } .centered-div { width: 200px; margin: 0 auto; position: relative; top: 50%; transform: translatey(-50%); }登录后复制
网格模板
.container { display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr auto 1fr; height: 300px; } .centered-div { grid-column: 2; grid-row: 2; }登录后复制
本文采摘于网络,不代表本站立场,转载联系作者并注明出处:https://www.iotsj.com//kuaixun/5482.html