PDA

View Full Version : New pure-CSS layout


DCElliott
12-09-2002, 05:03 PM
I have been working on a new pure-CSS layout that completely fills the page at *practically* all resolutions. This was a task I set myself after Zero's thread on getting the content to fill the page.

This *should* not have been hard. Set up a few horizontal divs with %age heights, what could be difficult. Well - making a template that works across browsers with a minimum of hacks is the most exasperating thing I have done in a long time.

Here are a few of the things I have learned:
Netscape needs a html {height:100%;} style - I think it must calculate all relative heights from this reference.
Rounding factors on the %heights of the divs means that you should set body {height:99%;} to "clip" the content before it gets >100% and forces a vertical scrollbar.
Rounding also means that you can't count on a there being a constant distance from the bottom - when you look at my template, you will see why this is important.
DOCTYPE declarations are very important in determining how the browser renders your page since it determines how the box dimensions are calculated.
Absolute positioning means you have to specify all the other dimensions more precisely. A relatively positioned div gets by quite happily with width:auto - not so for one absolutely positioned.
1st Page does not duplicate IE6 or IE5 exactly - as for Navigator 7 - forget about it. So keep two browsers running and check, check, check.
I ran into a width bug in IE6 that had IE6 behaving like IE5 when calculating the width of an absolute div. I had to use a conditional comment (seen at the end of the embedded styles) to override the stylesheet for IE.
If you set overflow:auto for the body in Navigator, you really, really, have to watch your composite widths (margin, border, padding and content)


So, I give you:
GHANJA style

This is a zip file (it has two files: the html and a small gif) - just unzip it and bring up ghanja.html. (I called it that because it is in the colors of the Jamaican flag - I hadn't planned it that way, it just happened. I wanted contrasting primary colors for the divs and went a bit overboard. :p It has nothing to do with certain extra-curricular activities :smoking:

There are a few interesting tricks in there and I hope folks can find something to talk about. to see it in all its glory, you should shut off the 1px borders that I left on to show up the edges of the content and footer divs. Can anyone tell me what footer-filler is for?

DCElliott
12-10-2002, 03:00 AM
David

I tested the template extensively in NN7 and have appended a screenshot below.

I haven't used Mozilla - the Mozilla.org website is an exercise in overkill - too much information. If you could steer me towards a less than bleeding edge compiled binary I would d/l it and add it to my suite. I've looked through my CSS again and don't see what would make it crash and burn.

My comment re 1st Page and NN was just that, although 1st will approximate IE rendering, you can't make any assumptions re NN - and now Mozilla shows that there are many variations of Gecko as well.

Glad you liked the transparency trick. :) I made a page once using partial alphas over a background that was way-cool but, of course, only worked in IE. This gets much the same effect. When we get greater support for PNG we well be able to do some really incredible stuff along these lines.

DCElliott
12-10-2002, 05:42 AM
David

Thanks for the pointer to an installation. When I went looking previously all I could find were source files and directions on "rolling your own" which is beyond this old fella's abilities at this point.

It appears that Mozilla likes to have the z-index of divs set explicitly. Other browsers will give each successive div a higher index and, because of the sequence in which the divs appeared, that behaviour worked - but not for Mozilla. I include here a modified style that works in Mozilla:<style type="text/css">
<!--
/*Placement and sizing*/

html {height:100%; margin:0; padding:0;}
body {height:99%; margin:0; padding:0;}
#superdiv {height:100%; width:100%;padding:1%; overflow:hidden;
voice-family: "\"}\"";
voice-family: inherit;
height:98%; width:98%; padding:1%; z-index:1;}
#banner {display:block; height:13%; width:auto; padding-left:24%; margin:0;
overflow:hidden;z-index:10;}
#middle {display:block; height:70%;width:auto; margin:1% 0%;z-index:10;}
#footer {display:block; height:13%; width:auto; padding:0%; margin:0%;
z-index:10;}
#footer-filler {display:block; position:absolute; top:auto; left:1%;
bottom:0 ; height:4%; width:98%; padding:0; margin:1% 0; z-index:2;}
#content {display:block; position:absolute; left:25%; top:18%;
height:63%; width:74%; overflow:auto;
margin: 0;z-index:100;}
#nav {display:block; position:absolute;
top:0; left:0; width: 20%; height:77%; margin:2%;
text-align:center; z-index:100;}

/*colors*/

body { background-color:#000;}
#banner {background-color:#f00;}
#middle{background-color:#ff0;color:silver;}
#footer {background-color:#093;
/*remove the following in actual use*/
border:1px dotted yellow;}
#footer-filler {background-color:#093;}
#content {scrollbar-base-color:#ff0;
scrollbar-arrow-color:#000;
scrollbar-highlight-color:#000;
/*remove the following in actual use*/
border:1px dotted black;}
#nav {background:transparent url(black_trans.gif) repeat;
color:#f00; border:thick solid black;}

/*buttons*/

#nav a.buttonred {display:block: width: 100px; height:auto;
text-decoration:none;
background: #f00; color:yellow;
font: bold 8pt/20pt 'courier new', courier, monospace;
vertical-align: middle; padding: 2px 2px;
border-top: 3px solid #f66;
border-left: 3px solid #f66;
border-right: 3px solid #c00;
border-bottom: 3px solid #c00;}
#nav a.buttonred:hover,#nav a.buttonred:active {
background: #e00;
border-top: 3px solid #c00;
border-left: 3px solid #c00;
border-right: 3px solid #f66;
border-bottom: 3px solid #f66;}
#nav a.buttongreen {display:block: width: 40px; height:auto; clear:both;
text-decoration:none;
background: #093; color:yellow;
font: bold 8pt/16pt 'courier new', courier, monospace;
vertical-align: middle; padding: 2px 2px;
border-top: 3px solid #396;
border-left: 3px solid #396;
border-right: 3px solid #063;
border-bottom: 3px solid #063;}
#nav a.buttongreen:hover,#nav a.buttongreen:active {
background: #083;
border-top: 3px solid #063;
border-left: 3px solid #063;
border-right: 3px solid #396;
border-bottom: 3px solid #396;}
#content h1, #content h2, #content h3, #content h4, #content h5
{width:80%;margin:.1em; padding-left:.5em;
border-left:.1em solid black;
border-bottom:.1em solid black;}

/*fix-ups for browser inconsistencies*/

#banner h1, #banner h2, #nav h1, #nav h2, #nav h3 {margin-top:0;}/*Needed by Gecko*/
-->
</style>

I've tried all sorts of tweaking to try to prevent the appearance of a vertical scrollbar, but it turns on at about 475px viewport height in Mozilla.

BTW - installing Mozilla has messed up my NN7 bigtime - Grrr!

dabbler
12-10-2002, 02:16 PM
Not very good at this, but I downloaded the zip file, unzipped it, started mozilla and opened the file and this happened:

dabbler
12-10-2002, 02:19 PM
OOps . sorry it's so big - told you I wasn't very good at it. but anyway - the page looks fine to me. - in Mozilla!!!!

What did I do wrong, that got it to work OK??

DCElliott
12-10-2002, 02:47 PM
Have done some additional work and now have the squishiest template I have ever done that still maximizes screen real-estate.

I have incorporated helpful suggestions from many folks. Thanks.

The ghanja style is now an external css with some annotation courtesy of Joel (ByteWizard) - a special thank you to you.

The attached zip has three files: ghanja2.html, ghanja.css and black-trans.gif that is used to make the pseudo-transparent #nav div.

Enjoy.

dabbler
12-11-2002, 01:12 AM
Goodness gracious me! I didn't realize I was being so helpful!

Glad that my little input has had some value.