views:

39

answers:

2

Hello,

I'm trying to have the following markup:

body
 #container
  #content

where body is full width and has a background snapping to the bottom right.

where container has a set width of 960px and min-width of 600px, located in the top left corner of the page.

where content has a set width of 600px and is also located in the top left corner of the page. with a margin "100px 0px 0px 100px"

When I try to do this, the body looks good with a background-attachment scroll positioned bottom right. However, when the browser is resized to a width of less then 960px (or any other width of the container element) the body stops at the width of the browser, leaking the subelements out.

I would like to have the body always be at least the width of the subelements, instead of it breaking. I have no elements floating, which could break up the page, so I don't see why it is behaving this way.

image indicating the problem

image indicating my wish

A: 

why not assign min-width to the body?

bazmegakapa
doesn't work, plus min-width (and min-height/max-width/max-height) are not cross-browser. I'd like a cross-browser option to solving this.
xaddict
+1  A: 

I've made a sort of solution over here:

jsFiddle

Put the min-width on the html element, not the body. Then if the viewport is too small, the background-image will move out of the viewport and is visible when you scroll.

Is this what you want?

Justus Romijn
I see in the comments below that you don't want to use min-width because it isn't cross-browser. Let me check if there is a better solution.
Justus Romijn
Also, I'd like not to use js, but do a full css solution :) thanks for the effort!
xaddict
for now, I'm adding the min-width. If there are other options to also make it work in for ex. IE6, IE6-, netscape, opera, etc. I will implement that alongside
xaddict
My example doens't use any javascript at all. jsfiddle is just a website to create on-the-fly front-end situations with html/css and/or javascript. In this case i don't use any javascript :)
Justus Romijn
I know... :) I just wanted to make clear that I prefer css only solutions as many people fall back to using javascript too fast. It's a kind of lazyness I don't like...
xaddict
I've found another problem. If the container inside the page exceeds the browser height it now doesn't update the background position. I've Fiddled it: http://jsfiddle.net/smXGv/
xaddict
change the height to "min-height". When setting the height of the html/body to 100%, it means the full viewport, not the full page. What you want is that the image is at the bottom of the viewport unless the page is larger then the viewport.
Justus Romijn
Thanks a bunch! I couldn't have figured this out without you... even though I have a lot of experience with css I often get confused about how the tricks impact each other. Wish I could give you more than one UP.
xaddict
You're welcome :)
Justus Romijn