div 垂直居中完美解决办法

2013-03-18 浏览:1471
div 垂直居中完美解决办法
评论:(0)复制地址

 

  1. html,body{   
  2.     height:100%;   
  3.   margin:0;   
  4.  padding:0;   
  5. }   
  6. body{   
  7.   background:#eae7d7 url(images/vert-centre.jpg) repeat-x center center;   
  8.     text-align:center;   
  9.     min-width:626px;   
  10.   min-height:400px;   
  11. }   
  12. #vert-hoz{   
  13.   position:absolute;   
  14.     top:50%;   
  15.   left:50%;   
  16.  margin-top:-198px;/* half elements height*/  
  17.    margin-left:-313px;/* half elements width*/  
  18.    width:624px;   
  19.   height:394px;   
  20.  border:1px solid silver;   
  21.   background:#666;   
  22.   overflow:auto;/* allow content to scroll inside element */  
  23.     text-align:left;   
  24. }   
  25. h1 {color:#fff;margin:0;padding:0}  
  1. <div id="vert-hoz">  
  2.  <h1>Content goes here</h1>  
  3. </div>  
评论:(0)复制地址
发布:苗景云 | 分类:IT技术&设计 | Tags:Div CSS

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。