2014-05-15 24 views
2

我試圖用Bootstrap顯示兩個彼此相鄰的div,但它們之間有一段距離。我怎麼能把他們完全相鄰。在引導程序中彼此相鄰的2格

的代碼:

<div class="col-lg-8 col-lg-offset-2 centered"> 
    <div style="float: left; border: 1px solid; width: 227px; height: 50px;"></div> 
    <div style="float: right; border: 1px solid;width: 227px; height: 50px;"></div> 
</div> 

圖片說明:

enter image description here

+1

他們爲什麼會彼此相鄰?單位浮起,左右浮動(每個都有一個小寬度),放在一個8列寬的容器中。您最好創建兩個col-lg-4 div或正確調整div寬度。 –

+0

爲什麼倒票?也許有一個具體的要求,將div的寬度設置爲227px? – mjwatts

回答

14

查找到引導grids

你可以做這樣的事情:

<div class="row"> 
    <div class="col-xs-6">div 1</div> 
    <div class="col-xs-6">div 2</div> 
</div> 
+0

不錯@lschlessinger,但是如果你不想要兩列'col-xs-6'會怎麼樣?而是兩個'col-xs-4'並且希望它們居中? – tblancog

+0

'

' –

+0

對於那些新引導,我認爲這需要在外部

才能正常工作。 – tbone

3

添加到Lschessinger的回答,您可以使用偏移中心的塊。看here偏移列

也許這就是你要找的?

<style> 
    .border {border: 1px solid #CCC;} 
</style> 

<div class="row"> 
    <div class="col-xs-2 border col-xs-offset-4">div 1</div> 
    <div class="col-xs-2 border">div 2</div> 
</div> 

或者,如果你要堅持與內聯樣式和具體寬度代碼,那麼也許這一點,你可以通過增加寬度454px到464px的10px的差距加大之間的寬度,依此類推:

<div class="col-lg-12"> 
    <div style="width: 454px;" class="center-block"> 
    <div style="border: 1px solid; width: 227px; height: 50px;" class="pull-left"></div> 
    <div style="border: 1px solid; width: 227px; height: 50px;" class="pull-right"></div> 
    </div> 
</div>