2

The problem i am facing with floated div is i have written this piece of code:

CodePiece1

but whenever i try add the class ;right' ,that makes it float to the right, to the button it jumps out of the wrapper div as

CodePiece2

How can i keep the left floated button inside the wrapper div rather then it being out of the wrapper div as in case of the second code.

deXter
  • 354
  • 4
  • 21

2 Answers2

4

Add overflow: hidden to the #buttonWrapper.

JSFiddle: http://jsfiddle.net/9Ecq2/8/

My Head Hurts
  • 37,315
  • 16
  • 75
  • 117
  • Thanks a lot.Can you please explain it too. – deXter Jan 15 '12 at 16:46
  • 1
    floated elements don't have a fixed location so parent elements can be unsure what to do with them. setting overflow to hidden forces the element to work out what size it is, therefore including the location of floated child elements, fixing your problem – MDEV Jan 15 '12 at 16:48
  • 2
    @deXter Here is an StackOverflow answer that explains it better than I ever could: http://stackoverflow.com/a/3416217/681807 – My Head Hurts Jan 15 '12 at 16:51
  • isn't overflow:hidden supposed to hide content overflowing out of the div block? – deXter Jan 15 '12 at 16:53
  • @deXter It does, but as mentioned by SmokeyPHP it also forces the element to extend to an appropriate size to fit the floating child elements. You can use `overflow: auto` if you wish but I find that sometimes causes scroll bars to appear. Check out [this link](http://css-tricks.com/the-css-overflow-property/) about the CSS Overflow property and navigate down to the "Float Clearing" section. – My Head Hurts Jan 15 '12 at 17:04
  • Thanks - A lifesaver for a CSS noob :-) – Morten Mar 20 '15 at 14:19
2

Add the style:

overflow:hidden;

to #buttonWrapper or #updateWrapper

MDEV
  • 10,730
  • 2
  • 33
  • 49