Home  >  Article  >  Web Front-end  >  由12306出错想到的div垂直居中的问题_html/css_WEB-ITnose

由12306出错想到的div垂直居中的问题_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:52:081146browse

今天想看看元旦回家还有没有余票,偷偷的打开了12306,开始查询回家的车票,结果发现,竟然查询不出来,再查直接出错了

看到这个很郁闷,很纠结,但是突然想到了最近一直想实现div垂直居中,赶紧试了一下12306这么大的网站肯定是可以垂直居中的,

试了一下,果然没有让我失望,适应各种分辨率垂直居中。

太好了,果然右键源代码

div class="err_text">                         <ul id="error" >                         <li id="err_top">                                                  </li>                                                  <li id="err_bot">  网络可能存在问题,请您重试一下!</li></ul></div>

然后再看一下css是怎么写的吧

.err_text{    position:absolute;    margin-top:-159px;        top:50%;    left:50%;    margin-left:-247px;    width:495px;    height:282px;}#error{    width:495px;    margin-left:auto;    margin-right:auto;    list-style:none;}#error li{    list-style:none;}#err_top{    background:url(err_top.gif) no-repeat;    height:78px;    line-height:78px;    width:495px;    }#err_bot{    background:url(err_bot.gif) no-repeat;    height:204px;    padding-top:50px;    width:495px;        text-align:center;    font-size:14px;    font-weight:bold;}

这时候聪明的你一定发现了,关键代码其实就是top:50%,left:50%,当然了前提是要绝对定位,这样就可以实现居中了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn