开发者

why does the containing div not recognize the height of the items within? [duplicate]

开发者 https://www.devze.com 2023-01-16 06:01 出处:网络
This question already has answers开发者_开发百科 here: What methods of ‘clearfix’ can I use?
This question already has answers开发者_开发百科 here: What methods of ‘clearfix’ can I use? (29 answers) Closed 9 years ago.

how can my containing div (boxes_blue) recognize the height of the items within?

#boxes_blue {
display: block;
margin: 0 0 0 175px;
border: 1px solid brown;
clear:  both; 
}

#boxes_blue_each {
float: right;
height: 100px;
width:  100px;
padding: 10px;
border-left: 3px solid #fff;
background-color: #004964;
color: #fffacf;
text-transform: uppercase;
text-align: left; 
}

<div id="boxes_blue"> <div id="boxes_blue_each">one</div> <div id="boxes_blue_each">two two</div> <div id="boxes_blue_each">three three three</div> <div id="boxes_blue_each">four four four four</div> </div>


This is happening because the divs that are contained all floated.

I am not sure why this is the way it is, but I know of a few solutions. Either set the containing div to have "overflow:hidden", or add another div below the floated divs with "clear:both". You could also, of course, set the height and width of the containing div as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消