tags:

views:

49

answers:

3

CSS is cool, but it's also kind of tricky, right?

I have three burning questions for you CSS masters:

  1. If I have a div id="a" with all default properties (in terms of positioning and such), and I place another div id="b" inside of it and set its width and height in pixels and also set the float: left property, why doesn't div id="a" resize its height to accomodate div id="b"? Is it possible to achieve that?
  2. I have the following situation: Layout Purple div is just a regular div (padding: 10px), white things are the items of the horizontally oriented ul list (again placed in its own div with float: left) and the green div is yet another div (display: inline-block) with the <p>A company</p> tag placed inside. The question is how do I make the div containing the list bottom align to the green div?
  3. And the last question, related to the previous situation: How do I make the green div stretch from the white div on the left to the end of the purple div on the right?

Thank you to everyone who understood my questions and is willing to share the answers!

A: 
  1. Read this: http://www.smashingmagazine.com/2009/10/19/the-mystery-of-css-float-property/

Sorry, but I don't understand the second and third question :(

Tae
Thanks for a rather quick reply. The link you've provided has answered all my questions. Cheers!
Boris
actually, there's only one more pickle to solve, and that is to bottom align white with the green div (question 2). i can always set the top margin for the white in order to move it down until it aligns with the bottom of the green div, but that's hard-coding which i hate. any thoughts?
Boris
You want to keep the height of the green div? I think if you have make the <ul> a inline-block, maybe the vertical-align property could work.
Tae
A: 
  1. i think this is because div#b is a child element, so, div#a - being the parent - will not inherit properties from div#b.
davidg
do you have the full html and css code for question 2? im wondering what you are actually floating...
davidg
Not quite - normally, a child element *would* cause a parent without fixed dimensions to expand, not because the parent 'inherits' its child's properties, but because it uses its child's dimensions to lay itself out. However, floats go against this rule - for good reason.
Bobby Jack
the solution is to set the `overflow: auto` for the purple div. that solves the first question. as for the third question, i just removed the `float: left` from the green div, and now it takes full width between the white and the right edge of the purple div.
Boris
there's only one more pickle to solve, and that is to bottom align white with the green div. i can always set the top margin for the white in order to move it down until it aligns with the bottom of the green div, but that's hard-coding which i hate. any thoughts?
Boris
woops, thanks bobby jack
davidg
A: 
  1. Here's an explanation: http://www.fiveminuteargument.com/float-container. In short, floated elements are expected to be able to span - for example - multiple paragraphs, so it wouldn't make sense for them to cause their containers to expand.
Bobby Jack
Thank you for your reply. Adding the `overflow: auto` to the purple div solved my problem regarding the question 1. there's only one more pickle to solve, and that is to bottom align white with the green div. i can always set the top margin for the white in order to move it down until it aligns with the bottom of the green div, but that's hard-coding which i hate. any thoughts?
Boris
I can't try this out right now, but here's a guess: now that the green div isn't floating, it should be able to size a container with both it and the white list inside it. You should then be able to position: relative that container and position: absolute, bottom: 0 the menu. Any chance that works?
Bobby Jack
well done bobby! thanks a million.
Boris