I am trying to create the CSS to match the attached image. I figure a picture is worth 1000 words, and probably faster and more accurate than me trying to explain it
This works, mostly. The layout matches the attached imageâŚbut the actual photo layer is not filling (I am assuming because everything inside it is floated??) and the bottom border of #photos is way up near the top of the layer.
Am I doing it wrong with floats? Is there an easier/better way?
a parent holding only floats⌠holds floats, which are more than nothing. the parent height is not affected by the floats height, true. like hanging out the clothes on a wire to dry, in which case the floats overflow the parent.
but then you hang the clothes in a wardrobe, that is, you are âclearingâ them. showing us he was always âtheir daddyâ
what i said is this: floats are taken out of the normal flow, inside their parent container, with regards to their sibling elements. when you move the parent, the floats move also. so the parent is acting as if it holds them.
your statement sounded more like saying that a parent with only floats will not contain them or control them: âparent that holds only floats holds nothingâ. it contains them all right, it just not fully contains them, hence the overflow.
you may not âseeâ the parent, but the parent holds the floats: when it moves they move. it just not containing the floats content (which is called overflowing) w/o clearing the floats. that is, it âactsâ as if he has no height, not like âit had no content at allâ. it does act about its content. zero height doesnât mean zero content, in our case means overflowed content. incorrect assertion from your part
and i think my clothing example is actually simple and accurate enough to be understood by anyone
Floats are removed from the flow and therefeore a parent that holds only floats holds nothing and has zero height.
In order to make the parent surround the float you need to use a clearing mechanism and overflow other than visible is the easiest to apply when you donât need visible overflow.
There are other methods that you can use but none so simple as the overflow method although you do also need to set haslayout on the parent element or ie6 wonât clear (which is easiest done with a dimension such as a width).
Folks, this thread was getting a bit nasty and flying off topic, so itâs closed now. Sorry Ylang if you had more questions. If so, just post a new thread.
lol - I think you just made it harder to understand
For all intents and purposes you can say that a parent that holds only floats will act as if it had no content at all. There will be no change or effect upon that element whether the float was there or not apart from the fact that foreground content will be repelled (or unless we create a new block formatting context which we can do with overflow other than visible (or display:table or display:inline-block).
Floats are removed from the flow as defined in the specs.
Since a float is not in the flow, non-positioned block boxes created before and after the float box flow vertically as if the float did not exist
Consider this example where the float is outside of the html for the element with a class of content yet the background of .content extends underneath the float.
What happens is that .content is laid out as if the float wasnât there (which it isnât because it is removed from the flow) and then the margins on the foreground content are adjusted so that they steer clear of the float and wrap around (or under) it.
The background and borders on elements adjacent to floats will act as if the float isnât there and will slide under the floats until they meet the containing block.
Also, padding: 30px 0 30px 0; can be written as padding: 30px 0;, #00ff00 as #0f0 and text-align: left is kinda redundant for western language browsers. If you do want to set that, Iâd recommend setting at the start of your css for all elements at once, instead of on every element separately :twocents: