Forum Moderators: not2easy

Message Too Old, No Replies

Page gets screwed up when the window resizes

Css layout noob

         

Guran

10:47 am on Jan 10, 2004 (gmt 0)

10+ Year Member



The page I am currently developing has a big problem. The page looks fine in fullscreen but if I resize the window and make it smaller everything gets screwed up.
The problem is that I position some divs using absolute positioning. I want these divs to be in the middle of the screen. I thought I should use 70% of the screen for my page. So the divs are positioned 15% from the left and their width is set to 70%. There are several divs positioned under each other. Their top position value is a static pixel value.
When I make the window smaller the browser attempts to keep the 15% from the left distance which makes my page look extremely ugly.
So what I need is basically that I get scrolls when the window gets smaller. How do I do that? I tried setting "overflow: scroll" for the body but that didnt help. By the way, overflow isnt supported on NS and opera right? If that is so I would prefer if this could be solved in a more browser friendly way.
Any ideas?

flump

11:32 am on Jan 10, 2004 (gmt 0)

10+ Year Member



on the main outter div (if you have one, if not create on) just put <div id="container"> main page here </div>
around everything, then set
#container {
position: relative;
}

hopefully that will solve your problem (hopefully) good luck.

grahamstewart

12:30 pm on Jan 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fluid designs are the way forward. You shouldn't assume your user has any particular screen size, instead have a flexible design that can deal with different resolutions.

Your going about it the right way by using percentages, but you need to completely avoid absolute pixel values.

You say "several divs positioned under each other" so can't you just use normal flow to position the divs vertically (and left and right margin set to auto to center them)?

The other problem with absolute pixels values is that if the user increases the font size then the text may get clipped by an absolute div, whereas a normal div will expand to contain it.

Guran

4:24 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



It doesnt seem to help. I did a test page to see what happens if I just have a page with 15% padding on the left and right. I put this padding in the body tag. I then put a div in the page with a specified height of 150 pixels. No other positioning or sizing of that div. The problem remains the same. When the window size is decreased I dont get any scrollers, instead the div width is decreased.
If I put a pixel size on the width of the div, it works. But I cant do that because the page will look different on different resolutions which I dont want, thats the reason I want a percentage width of the page.

phoenix09

11:45 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



This works, the scroll bar appears when you resize the page as you want:


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
.container {width:100%;padding-left:15%;padding-right:15%;background-color:blue;}
</style>

</head>

<body>
<div align="center" class="container">
<div style="height:400px;background-color:red;">
</div>
</div>
</body>

</html>

you need to have the container be the primary div tag, as another person noted, not the body tag. The body tag is very unreliable if you want to use it to create padding and or margins, opera for example treats it differently than most other browsers.

grahamstewart

2:27 am on Jan 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> When the window size is decreased I dont get any scrollers, instead the div width is decreased.

This is a 'good thing'. You can't assume everyones browser window is going to be the same size as yours. Your better off producing a design that copes well with the resizing, rather than forcing a horizontal scroll bar.

Say you decide (as many do) "Okay I'll take the easy way out and make my page a static 750px width - that way it will look the same in everything from 800x600 upwards"

But then..

What about those who have the 'Explorer Bar' open?
What about those on portrait displays?
Or those with PDA browsers?
What about all the wasted space on larger displays?
Or even those who just don't always surf with the window maximised?

However, if you do choose the dark side, then the easiest way is probably just to stick it all in a container div and set the width of the container to an absolute value (e.g. 750px or similar). Then you can center the container div so at least the page appears centralised on larger displays.

note: the static vs fluid design jihad has been done to death on this site see many, many other posts for prolonged discussions on the benefits and pitfalls of both.

grahamstewart

2:32 am on Jan 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Incidentally
<div align="center"> 
won't validate if you are using a strict doctype, because align is a deprecated attribute.

Instead just set the left and right margin of the div to auto using

margin: 0 auto;
in the CSS.

Guran

9:45 am on Jan 11, 2004 (gmt 0)

10+ Year Member



But if people use a very small window. The problem there would be that items get on top of each other. when the window gets to small. So in order for the page to keep its intended appearance I thought scrollers would be better.

The code you provided doesnt work for me Phoenix. When the window gets smaller, it still keeps its 15% padding of the current window size. I want it to have 15% padding of the maximum window size. And if the window gets smaller than the page width, you have to scroll the page to see the full width of it. Maybe I wasnt completely clear on that.

grahamstewart

12:35 pm on Jan 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The trouble is that when you specify a percentage width it means a percentage of the window size, not of the screen size, so obviously if you make the window smaller the width of the div will shrink.

Guran

4:01 pm on Jan 11, 2004 (gmt 0)

10+ Year Member



So basically if I want to do it the way I want I have to use a pixel value for the width?

phoenix09

10:10 pm on Jan 11, 2004 (gmt 0)

10+ Year Member



this forum topic might or might not point you in the right direction:
[webmasterworld.com...]
Notice however that the results are not reliable, or predictable, or consistent cross browser.

If I were you I'd just declare the main content div body as fixed width and forget trying to get this percent stuff working, that's what I usually do, set it as maybe 750px wide, then just center it, using either align="center" if you aren't using a strict doc type or the margin: 0 auto; method above, which I haven't had much luck with personally, especially on older browsers, which is why I don't use it.

grahamstewart

10:59 am on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



phoenix09: to cover yourself in older browsers that don't support auto margins you can set
text-align: center
on the parent div as well.

Shadows Papa

3:11 pm on Jan 12, 2004 (gmt 0)

10+ Year Member



Please don't force horizontal scroll bars. Most of us hate them!
Fluid, as was said earlier, is the way to go.
Pages are best read if there are 5 to 7% margins left and right. Scrollbars make it not only harder on the eyes, but harder on the hands - you must scroll left and right PLUS the normal up and down.
Avoid them.

Shadows Papa

Guran

5:15 pm on Jan 12, 2004 (gmt 0)

10+ Year Member



I restarted the project, now with fluid design in mind.