2016-11-24 5 views
-1

Ich möchte einfach eine rote Grenze über die #cont hinzufügen, aber wenn ich diese drei Boxen schweben die Grenze funktioniert nicht und es kommt nur oben nicht Wrapping all die div.wie auch immer ich verwenden kann Überlauf: auto. es funktioniert, aber ich wollte nur wissen, warum es nicht ohne Überlauf funktioniert.Grenze in css nicht passend nach div

HTML:

<div id ="cont"> 
    <div class ="box" > box1 </div> 
    <div class ="box" > box2 </div> 
    <div class ="box" > box3 </div> 
</div> 
<div id="foo">footer</div> 

CSS:

#cont { 
    width:950px; 
    border:1px solid red; 
} 
.box { 
    width:300px; 
    height:100px; 
    border:1px solid black; 
    background-color:orange; 
    float:left;  
} 
#foo { 
    width:100px; 
    background-color:blue; 
    clear:both; 
} 

enter image description here

+0

Sie den Link zu Ihrem jsfiddle teilen können so tweek wir können es –

+0

Sie [clearfix] (http://stackoverflow.com/questions/8554043 brauchen/what-is-a-clearfix) – giorgio

+0

@Raheel Geben Sie den Link –

Antwort

0

Floated divs wird nicht das Haupt div nach dem childs.add ein zusätzliches div wachsen lassen um die Hauptdivs-Höhe beizubehalten.

<div id ="cont"> 
    <div class ="box" > box1 </div> 
    <div class ="box" > box2 </div> 
    <div class ="box" > box3 </div> 
    <div class ="clrfx" > </div> 
</div> 
<div id="foo"> footer </div> 

und die CSS für neue div

.clrfx{ 
    clear:both; 
} 
-1

Verwenden Display:inline-block Eigenschaft in Ihrem Kasten

#cont{ 
 
width:950px; 
 
border:1px solid red; 
 
float:left; 
 
} 
 
.box{ 
 
    width:300px; 
 
    height:100px; 
 
    border:1px solid black; 
 
    background-color:orange; 
 
     float:left; 
 
     display:inline-block; 
 
} 
 
#foo{ 
 
    width:100px; 
 
    background-color:blue; 
 
    clear:both; 
 
}
<div id ="cont"> 
 
    <div class ="box" > box1 </div> 
 
    <div class ="box" > box2 </div> 
 
    <div class ="box" > box3 </div> 
 
</div> 
 
<div id="foo"> footer </div>