Hello, I'm currently attempting to write a layout for my blog. However, I am running into problems when attempting to have a background image repeat in the background div. Basically, I have a container that holds all my divs. I also have a content div which basically holds the stuff inside the container(the blog div and my nav div). However, when trying to get the image on my content div to repeat it doesn't work. Here is my code. I also made it inline css right now for the sake of testing. One thing I also tried doing was creating a skeleton of my current layout with the divs and no content in them and I ran into the same problem. Any help would be very much appreciated. Thanks
My guess would be because Nav and Blog are floated, #contentContainer doesn't have any height so the background image isn't showing.
You should clear those two floats before you close out contentContainer, which should show the background when the container expands to its floated contents.
Now let's say that we give #wrapper a background color of red, and float #left-nav left, and float #content right.
We view our page expecting to see #left-nav and #content beside each other, which they are, but there's no red background? Why?
Well, this has to do with "normal flow" which is the default positioning the browser renders elements. If we didn't float #left-nav and #content they'd never be able to be beside each other, because by default they're block-level elements and render on top of each other.
By floating the two inner divs, we take them out of normal flow which allows them to position beside each other--this is the effect we want, but the problem is now since both of #wrappers content divs are floated there's technically nothing contained inside of it in normal flow. This means that when #wrapper goes to compute its height it thinks its height is zero, because there's nothing inside of it in normal flow. That's the reason why the red background would not show in this example, and in your case as well.
"clear" is a CSS property that handles this problem. When you clear floats, it forces the containing divs to expand its size to include the size of its floats. You can accomplish this by the following:
Now, because the two floats are cleared (you can clear left, right, or both) #wrapper will expand its height to include the height of #left-nav and #content, and because #wrapper has a height now the red background is shown.
This crude ascii drawing describes this phenomenon visually:
WOW that is a great explanation! good visual to back it up. I have a question to take it one step further. Taking the same scenario, if we clear:left that would extend the height of the wrapper beyond the left-nav and allow the content div to flow over and beyond the wrapper?
WOW that is a great explanation! good visual to back it up. I have a question to take it one step further. Taking the same scenario, if we clear:left that would extend the height of the wrapper beyond the left-nav and allow the content div to flow over and beyond the wrapper?
Thanks for the kudos guys!
Yes toothmkr, that's exactly what would happen. When you specify a specific direction on the clear (such as left, or right), it only considers elements that are floated in that direction. In your example, if the #left-nav was shorter than #content and you cleared left, then #wrapper would only expand to cover #left-nav.
Hmm...We had a non-technical thread regarding ASCII-art(I thought it is just for fun) and now I think its the time to start a separate sub-forum for ASCII-art.
It's always a big problem to explain many matters through web since there is no easy and efficient way to pictorially represent a problem . For instance if someone explain something in trigonometry, instead of saying like "let ABC be a triangle where side AB, angle B .....", it would be many times easier if we can draw it by mouse.
Will this ASCII-art serve this purpose? Come on, lets share and learn this new technique.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
I have another question. I am only asking because I am truely beginning to understand whats up. Say we take the last scenario and add another div below the wrapper but we want to keep it left of the content div. would it get written like this?
You'll notice in this case I replaced the clearing div with a footer div, which can serve dual-duty by having both a clear: both in its CSS rules, and also typical hold footer information.
This skeleton makes up the basic two-column layout for CSS.
In your example, since "#next-div" is outside of #wrapper, and you cleared the floats in #wrapper, it would float left in a similar manner to #left-nav, BUT it would appear below #wrapper since it was cleared first.
By putting #next-div inside of #left-nav, you'd achieve the result you wanted which is #next-div floating left of the content, and directly below the nav content in the left column:
Will this ASCII-art serve this purpose? Come on, lets share and learn this new technique.
ASCII art is old as dirt. Back in the day we used to connect to bulletin boards with our fancy 2400 baud modems and all you got back was either ASCII or ANSI characters, which a lot of pretty skilled people had purposed to represent crude graphics (although in the case of ANSI art, some people were really able to pull off some awesome stuff).
There's no magic to making it with a mouse, it's just sitting there with a fixed-proportion font and tweaking it around until it looks right. =) Pretty easy to use for simple things like boxes and straight-lined explanations though.
ASCII art is old as dirt. Back in the day we used to connect to bulletin boards with our fancy 2400 baud modems and all you got back was either ASCII or ANSI characters, which a lot of pretty skilled people had purposed to represent crude graphics (although in the case of ANSI art, some people were really able to pull off some awesome stuff).
There's no magic to making it with a mouse, it's just sitting there with a fixed-proportion font and tweaking it around until it looks right. =) Pretty easy to use for simple things like boxes and straight-lined explanations though.
OK,all that I wanted to convey is it's hard in web to represent such problems/solutions without any graphic editors. (I,ve been in search of such a program by which one can draw and save his image along with his text data. When I saw his explanation, quite surprised.)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)