Forum Moderators: not2easy

Message Too Old, No Replies

100% width div

it's not really 100% in either browsers

         

norbiu

6:45 pm on Mar 31, 2007 (gmt 0)

10+ Year Member



I have a div set at width: 100% so it covers the whole page. It looks great but when I make the browser smaller the horizontal scrollbar kicks in and when I try scrolling to the right, the div has a huge gap. Is there a way to fix this?

Xapti

7:01 pm on Mar 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First and most important thing: Make sure you have body{width:100%}
that's probably the problem.

Second, try adding
*{margin:0;padding:0;border:0} to your CSS, if you haven't already.

Also, make sure you test the situation in the simplest way. Make a new html file and just make a div in the body, and size it to 100% width, and see if it works.

Ensure you're using a good doctype. Right now,
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
is a pretty good choice, but you could use strict mode too.

so I made a simple test file, and it worked perfectly. I even removed body:100%, and it worked perfectly. Running on IE 6 and FF 2.

If for some reason content (image, or something) is too wide, it will still horizontally scroll. and if you dont' want that, then add divid{overflow:none} I think.

[edited by: Xapti at 7:07 pm (utc) on Mar. 31, 2007]

norbiu

7:34 pm on Mar 31, 2007 (gmt 0)

10+ Year Member



Still doesn't work. I rewrote everything, but I don't know where the problem is.

Try scrolling to the right after you resize the browser to be smaller than the content div.

<html>
<head>
<style>
body {
width: 100%;
}

.banner {
width: 100%;
background-color: #999;
}

.content {
width: 950px;
border: 1px solid #333;
height: 100px;
}
</style>
</head>

<body>
<div class="banner">
this is the banner
</div>

<div class="content">
this is the content
</div>

</body>
</html>

Dabrowski

8:23 pm on Mar 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok, I think I have the answer.

Xapti, it's 'overflow: hidden'

norbiu I copied this example with a strict doctype and I think I know what's happening.

Your banner is 100%, when you shrink the browser this also shrinks with the browser.

Your content is 950px, so when you shrink the browser this scrolls off the screen.

From my point of view, the 'huge gap' you are seeing is because the banner is now smaller than the content div, so a gap appears to the right of the banner.

The 100% is referring to the browser width, not the content width.

Is that it?

norbiu

8:56 pm on Mar 31, 2007 (gmt 0)

10+ Year Member



Yes, that's the problem. I found a solution but I don't know whether it's correct or not.

Instead of having width: 100% in .banner I put a max-width: 1500px; (or higher) and min-width: 950px; (equal to the content width).

Edit: There still is a gap when I scroll, but it's not as big (just a couple of pixels)

Dabrowski

12:09 pm on Apr 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think this small gap is for the V scrollbar. I know there isn't one, but I think IE still leaves space for it, don't know about FF. It's about 15px I think.

The only way you can get around this is by 'overflow-y: hidden' but then your page can't scroll downwards, unless you use a wrapper and have one scrollbar on body, one on the wrapper but it really starts to get messy that way.

norbiu

12:40 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



I'm going to leave it like that. Nobody could even notice it anyway :) Thanks for the help!