>  기사  >  웹 프론트엔드  >  由12306出错想到的div垂直居中的问题_html/css_WEB-ITnose

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

WBOY
WBOY원래의
2016-06-24 11:52:081145검색

今天想看看元旦回家还有没有余票,偷偷的打开了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%,当然了前提是要绝对定位,这样就可以实现居中了

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.