I am not a professional web-developer but I am designing one to help out a no-profit organization.
I spent a couple of days searching the web for instructions and explanations on css, float, position, etc. Finally I managed to design the layout I wanted with the behaviour I wanted but there is still something that is not working/I do not understand.
Please, see the page at: “http://www.missione-berna.ch/index2.php” and its source; I put all the code in it to make it accessible (at the end stiles, scripts, menu and header will be in separate files included eventually via php).
How come that my “Menu” div is neither the size of its content nor the size of the neighbour “Contenuto” div?
I understood that it is not an easy task to have the height of two div column match, but where is this “mid-way” size coming from?
Any help appreciated, thansk in advance.
I am not a professional web-developer but I am designing one to help out
Share
First of all,
position: absolutecan be a Very Bad Thing. Avoid it unless trying to take elements out of the flow of the page (having one element appear on top of another).Second,
height: 100%does not do what, intuitively, you’d think it does. You’re setting the height of the menu div to 100% of the viewport’s height (your browser window), not 100% of the entire page.Since your menu has a simple background, there’s a neat trick you can use to make it appear to be the same height. CSSDesk
I’ve added a wrapper div around your menu and content. Relevant bits of HTML:
And styled it like so:
So the entire thing has a gray background. Your menu is floated left (over the gray background). The contentuo div has a left margin of 192px to “clear” the menu, and has a white background to hide the gray. The wrapper and content divs, and thus the gray/white backgrounds, will expand to the size of your content.
A couple tips:
height: 100%.float: leftorfloat: rightinherently set
display: block. You can’t setdisplay: inlineonfloated elements.