Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep floating div inside frame of parent div?

Tags:

I have a div containing several other divs with setting float:left. Now I want a frame around all of them, so i put a border on the parent div, but the floating ones "flow" out of the frame...

CSS:

.rendering {     padding-left:10pt;     border-width: 1px;     border-style: solid; } .column {     float:left;     padding-left:10pt; } 

Html:

<div class="rendering">     <div class="column">         <img class="ImagePlugin" src="some-image">     </div>     <div class="column">         <span class="phone">999</span>         <span class="name">Assange</span>     </div> </div> 

What can I do (in CSS) to keep them inside the parent frame?

like image 370
Cedric Reichenbach Avatar asked Jan 26 '12 10:01

Cedric Reichenbach


People also ask

How do you make things stay inside a div?

Just add overflow: auto; to the <ul> . That will make it so that the text doesn't leak outside of the UL. However, depending on what you're doing, it might be easier to just make the <li> display: inline; . It totally depends on what you're doing!

How do I make DIVS always fit in my parent div?

For width it's easy, simply remove the width: 100% rule. By default, the div will stretch to fit the parent container. Height is not quite so simple. You could do something like the equal height column trick.

Can we keep div inside TD?

No, you cannot insert a div directly inside of a table.


2 Answers

add overflow: hidden to your parent <div> - http://jsfiddle.net/5AVA8/

.rendering {     padding-left:10pt;     border-width: 1px;     border-style: solid;     overflow: hidden; } 
like image 109
Zoltan Toth Avatar answered Sep 24 '22 14:09

Zoltan Toth


You're not clearing the floats. If you change your code to this it will solve your problem.

.rendering {     padding-left:10pt;     border-width: 1px;     border-style: solid; } .column {     float:left;     padding-left:10pt; }  .clear {      clear: both;    }  <div class="rendering">     <div class="column">         <img class="ImagePlugin" src="some-image">     </div>     <div class="column">         <span class="phone">999</span>         <span class="name">Assange</span>     </div>      <div class="clear"></div> </div> 

See the example I've set up here - http://jsfiddle.net/spacebeers/RQNDr/

For more information on the clear property - http://css.maxdesign.com.au/floatutorial/

like image 44
SpaceBeers Avatar answered Sep 23 '22 14:09

SpaceBeers