Open yyman001 opened 7 years ago
//固定高宽 .absolute{ position: absolute; width: 200px; height: 200px; top: 50%; left: 50%; margin-top: -100px; margin-left: -100px; background: red } //非固定高宽 .absolute2 { position: absolute; top: 0; right: 0; left: 0; bottom: 0; margin: auto; //关键 background: red }
float
.table-cell{ display: table-cell; vertical-align: middle; text-align: center; width: 120px; height: 120px; background: purple; }
.line-height { width: 120px; height: 120px; line-height: 120px; }
.translate { position: absolute; width: 80px; height: 80px; top: 50%; left: 50%; transform: translate(-50%, -50%); background: green; }
.pseudo-class{ position: fixed; display: block; top: 0; right: 0; bottom: 0; left: 0; text-align: center; background: rgba(0, 0, 0, .5); } .pseudo-class:before { content: ''; display: inline-block; vertical-align: middle; height: 100%; } .pseudo-class .content { display: inline-block; vertical-align: middle; width: 60px; height: 60px; color: red; background: yellow; }
float
一起适用,会失效; 解决办法:再套多一个容器用float