I am trying to float some elements and apply clearfix so that the parent element can expand to the height and width of the children.
So, I simply set up the layout as per this fiddle: http://jsfiddle.net/fMjEx/
I then wanted to float the elements inside .bar. This is usually quite straight forward:
- Float the elements.
- Clear fix the parent using
pie-clearfixoroverflow: auto.
However, I ran into these problems:
-
If I use pie-clearfix, the element
.picturewhich is next to.baris also included in the clearing: http://jsfiddle.net/6C7WD/ -
If I use
overflow: autooroverflow: hidden, the width of the.barno longer spans the width of the document: http://jsfiddle.net/fv2gA/
Initially, one solution I had was to make .picture position: absolute. However, the problem with this approach is that the element is taken out of the flow.
In the layout, the height of .bar is variable depending on the content inside. I would like to give .bar and .picture a margin-bottom so that anything that comes after them is pushed downwards by that amount depending on whether .bar or .picture has a greater height.
This rules out using position: absolute on .picture as a solution.
Are there any solutions that satisfy the following?
- Clear only floats within
.bar. - Does not remove any elements from the flow.
This is the solution I ended up with:
Added a wrapper to the markup:
And the CSS:
Fiddle of the above: http://jsfiddle.net/c6Lng/