2013-08-25 43 views
2

我想居中(margin auto)div,哪個父div是相對的。居中div div是哪個父div是相對的

<div id="header-layout"> 
     <div class="left"> 
      <div class="facebook-like"> 
       <div class="fb-like" data-href="http://developers.facebook.com/docs/reference/plugins/like" data-layout="button_count" data-show-faces="true" data-send="false"></div> 
      </div> 

      <div class="twitter-follow"> 
       <a href="https://twitter.com/StereoShoots" class="twitter-follow-button" data-show-count="false" data-lang="ru">Читать @StereoShoots</a> 
       <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> 
      </div> 
     </div> 

     <div class="center"> 
      <div class="header-center"> 
       trying to center this div (header-center) 
      </div> 
     </div> 

     <div class="right"> 
     right 
     </div> 
    </div> 

CSS

#header-layout { position: relative; } 
#header-layout DIV { position: absolute; } 

.left { background: #C7E3E4; width: 290px; } 
.center { background: #E0D2C7; left: 290px; right: 200px;} 
.right { background: #ECD5DE; width: 200px; right: 0; } 
.facebook-like {} 
.twitter-follow {left:135px;} 

.header-center{width:300px;background:red;margin:0 auto;} 

還沒定心.header中心 - 解決方案請!

謝謝!

+0

你對'所有*後代*'div'元素應用了'position:absolute;'是什麼東西?我想會有更好的方法來實現你的目標。 –

+0

不是全部,只在標題佈局 –

+0

我意思是所有的後代元素。 –

回答

1
.absolute-center { 
    position:absolute; 
    left:0; 
    right:0; 
    margin:auto; 
} 

以中心horizontally