我需要顯示兩個彼此相鄰且具有不同背景的<div>
。Div在浮動後不會顯示背景顏色:左邊
不幸的是,第二個<div>
的background-color
被忽略。我已閱讀了一些帖子,並且人們建議添加clear:both;
。不幸的是,這並沒有幫助。有沒有辦法如何獲得background-color
的.div2
?
CSS:
.div1 {
margin-top:10px;
float:left;
background:blue;
width:382px;
padding:0 5px 10px 10px;
}
.div2 {
margin-top:10px;
width:374px;
background:red;
padding:0 10px 10px 0;
}
.clear {
clear:both;
}
HTML:
<div class="div1">DIV1</div>
<div class="div2">DIV2</div>
<div class="clear"></div>