2015-12-14 69 views
-3

Required layout如何在對面的頂部和底部div之間插入div?

我想將div放在左邊和底部div之間。每個寬度必須爲40%。我試圖在沒有Javascript的情況下做到這一點。

#left_col,#right_col,#bottom { 
    width: 40%; 
    height:200px; 
    float:left; 
    clear:left; 
    padding: 0; 
    border: #0BDC00 solid 2px; 
} 
#right_col{ 
    float:right; 
    clear:right; 
    text-align: right; 
    display:table-cell; 
} 
+1

請始終包括你有什麼到目前爲止已經試過。 – LinusGeffarth

+0

你是什麼意思「把正確的div之間的左側和底部div」?你的意思是標記,或通過JS/jQuery的點擊事件或什麼? – AdamJeffers

+0

,就像你在圖像上看到的那樣 – Flipz

回答

1

代替使用clear:leftclear:right使用clear:both代替;

#left_col,#right_col,#bottom { 
    width: 40%; 
    height:200px; 
    float:left; 
    clear:both; 
    padding: 0; 
    border: #0BDC00 solid 2px; 
} 
#right_col{ 
    float:right; 
    clear:both; 
    text-align: right; 
    display:table-cell; 
} 

Fiddle

0

*, 
 
*:before, 
 
*:after { 
 
    box-sizing: inherit; 
 
} 
 
html { 
 
    box-sizing: border-box; 
 
} 
 
html, 
 
body { 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 
body { 
 
    background-color: #F72F4E; 
 
} 
 

 
.Container { 
 
    width: 600px; 
 
    padding: 20px; 
 
    border: 1px solid #000; 
 
} 
 

 
.Row { 
 
    display: flex; 
 
} 
 

 
.Row:nth-of-type(odd) { 
 
    justify-content: flex-start; 
 
} 
 

 
.Row:nth-of-type(even) { 
 
    justify-content: flex-end; 
 
} 
 

 
.Row__item { 
 
    width: 40%; 
 
    background: #000; 
 
    height: 60px; 
 
}
<div class="Container"> 
 
    <div class="Row"> 
 
    <div class="Row__item"> 
 
     
 
    </div> 
 
    </div> 
 
    <div class="Row"> 
 
    <div class="Row__item"> 
 
     
 
    </div> 
 
    </div> 
 
    <div class="Row"> 
 
    <div class="Row__item"> 
 
     
 
    </div> 
 
    </div> 
 
</div>