6种不同的CSS实现垂直水平居中
6种不同的CSS实现垂直水平居中:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Custom Analytics Model</title> <style> .box{ width: 200px; height: 200px; background: #cccccc; margin-top: 10px; } .box1{ display: table-cell; vertical-align: middle; text-align: center; } .box1 span{ display: inline-block; } .box2{ display: flex; justify-content:center; flex-direction:column; text-align: center; } .box3{position:relative;} .box3 div{ position: absolute; top:50%; left:50%; width:100%; transform:translate(-50%,-50%); text-align: center; } .box3 span{ display: inline-block; } .box4{ text-align:center; font-size:0; } .box4 div{ vertical-align:middle; display:inline-block; font-size:16px; } .box4 span{ display: inline-block; } .box4:after{ content:''; width:0; height:100%; display:inline-block; vertical-align:middle; } .box5{ display: flex; text-align: center; } .box5 div{ margin: auto; } .box5 span{ display: inline-block; } .box6{ display: -webkit-box; -webkit-box-pack:center; -webkit-box-align:center; -webkit-box-orient: vertical; text-align: center; } .box6 span{ display: inline-block; } </style> </head> <body style="background-color: #f9fafc; margin:0px;"> <div class="box box1"> <span>1垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> <div class="box box2"> <span>2垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> <div class="box box3"> <div> <span>3垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> </div> <div class="box box4"> <div> <span>4垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> </div> <div class="box box5"> <div> <span>5垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> </div> <div class="box box6"> <span>6垂直居中垂直居中垂直居中垂直居中垂直居中</span> <span>垂直居中</span> </div> </body> </html>
相关推荐
afeichuanqi 2019-06-29
realitycss 2019-06-28
lyg0 2020-03-07
hhhkhhh 2017-07-20
hellowzm 2020-07-19
drdrsky 2020-06-04
XuNeely 2020-04-22
tianzyc 2020-02-17
沈宫新 2020-01-02
impress 2020-01-02
89510194 2019-12-31
wwwxuewen 2019-12-19
hlfsunshine 2013-09-02
lcyangcss 2019-11-10
zhangpan 2019-11-09
liushi 2007-11-13
超哥Blog 2007-09-30
libowenhit 2007-09-27