2014-11-04 75 views
0

我正在建立一个引导站点,我在我试图使中心页面的中心divs。我不能为我的生活弄清楚。任何人都知道为什么它不会居中?我试过了:div将不会在引导中心

margin: 0 auto; 
text-align: center; 

在几乎有史以来的元素,我不能让它去。感到沮丧在这里。下面是该网站的链接,所以你可以看到我在谈论http://bit.ly/1wYQDD1

以下是部分代码的样子,你可以在现场检查它看多:

<section class="no-margin" id="main" style="background-image:url(/GulflifeRealty.com/images/images/<%=img%>); height:650px; background-size:cover; background-position:0 -210px; background-repeat:no-repeat;">  
    <div class="container"> 
     <div class="row"> 
      <div class="col-lg-12"> 

      <div> 

       <a href="http://matrix.swflamls.com/Matrix/Public/IDXSearch.aspx?count=1&idx=f25b59c&iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]"><div class="homeBox" style="background-image:url(/GulflifeRealty.com/images/images/<%=listings%>);"> 

       <h3>See our Listings</h3> 


       </div></a> 

       <a href="http://matrix.swflamls.com/Matrix/Public/IDXSearch.aspx?count=1&idx=b03d59b&iframe=true&width=100%&height=100%" rel="prettyPhoto[iframes]"><div class="homeBox" style="background-image:url(/GulflifeRealty.com/images/images/<%=mls%>);"> 
<h3>Search the MLS</h3> 

  </div> 
     </div> 
    </div> 
</section> 

回答

2

您无法使用中心text-align: center两个<div>是因为你使用float: left吨o使它们显示为内联。您需要使用display: inline-block,而不是float: left,像这样:

.homeBox { 
    display: inline-block; 
    float: none; 
} 

然后容器text-align属性设置<div>center,像这样:

row > div { 
    text-align: center; 
} 

它完美:

enter image description here

+1

WOW !!!!!我有这种与CSS的爱恨关系。谢谢你清理那个。我会接受,当这件事让我(7分钟) – Damien 2014-11-04 02:24:54

+1

+1为伟大的答案和视觉 – Christina 2014-11-04 02:28:43