Forum Moderators: not2easy

Message Too Old, No Replies

Could you check my CSS for stupidities please?

About to launch first-time site

         

mooperlee

7:32 pm on May 10, 2007 (gmt 0)

10+ Year Member



I am about to put my brand spanking new site online, and before I do I was hoping some seasoned CSS experts could take a quick look at my code and see if there is anything cretinous in there. It's built using XHTML and CSS for layout and styles.

I've checked the site in IE 5.5, IE6 and IE7 and also latest Firefox version, all looks OK. Also the xhtml and CSS verify under the W3C verification thingie.

Basically I'm just looking for anything that might cause problems in more obscure browsers or for people with unusual browser settings, that type of thing. Also anything that can be simplified. I'd be very grateful for any suggestions.

My Doctype is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

Here's the CSS file (I've left out the code for things like h1, h2 etc as I'm pretty sure they're OK):

html {height: 100%; margin: 0px;}
body {margin: 0px; padding: 0px; text-align: center }

div#container{position:relative;text-align:left;background: url('images/border.gif') repeat-y 0 0}
div#headerlinks{position:absolute;top:41px;left:718px}
div#splash{background:#617192}
div#links{background:#000000;text-align:center;padding-top:6px}
div#links p{font-family:Verdana;font-size:11px;color:#FFFFFF;margin-bottom:5px}
div#links a{color:#FFFFFF;text-decoration:none}
div#navigation{position:absolute;left:0%;background:#617192;padding:10px;border-left-style:solid;border-left-width:1px}
div#navigation p{color:#FFFFFF}
div#navigation h1{color:#FFFFFF;margin:0}
div#content{position:relative;left:180px;padding:10px;background: #FFFFFF url('images/shadow.gif') repeat-y 738px 0px;
border-left-style:solid;border-left-width:1px}
div#footer {background:#FFFFFF;text-align:center;border-top-style:solid;border-top-width:1px}
div#footer p{font-size:11px}

div#container{width:920px;margin:0 auto}
div#headerlinks{width:200px;height:10px}
div#splash{width:100%;height:140px}
div#links{width:920px;height:22px}
div#navigation{width:160px}
div#content{width:720px}
div#footer{width:920px;height:30px}

Demaestro

7:37 pm on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Looks pretty clean..

The only thing I would do is change this:
url('images/border.gif')

to this:

url('/images/border.gif')

I added a forward slash. It is more good programing practice then anything.

Other then that it looks good although I don't know much about the 'repeat - y' stuff. There may be other ways of doing what you are accomplishing there..... the only reason I bring it up is it is unfamiliar to me.

[edited by: Demaestro at 7:38 pm (utc) on May 10, 2007]

Robin_reala

9:40 pm on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looking just at code efficiency there are some small gains to be made:
  • For a start, ids are unique to a page so you don't need to reference the element type as well (e.g.
    #container
    instead of
    div#container
    ).
  • Values of
    0
    are always
    0
    , regardless of unit, so we can dump them (e.g.
    0
    instead of
    0px
    ).
  • Hex colours can be reduced if they consist of three blocks of two of the same digits to three blocks of the single digit (e.g.
    #abc
    instead of
    #aabbcc
    ).
  • You could also use some more shorthand (e.g.
    font: 11px Verdana;
    instead of
    font-family:Verdana;font-size:11px;
    ).
  • Actually, on the font note it's best practise to provide a generic font family after your chosen font, so in this case
    font: 11px Verdana;
    should be
    font: 11px Verdana, sans-serif;
    .

[edited by: Robin_reala at 9:41 pm (utc) on May 10, 2007]

penders

11:26 pm on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The only thing I would do is change this:
url('images/border.gif')

to this:

url('/images/border.gif')

I added a forward slash. It is more good programing practice then anything.

To change the image path from one that is relative to the CSS file, to one that is relative to the webroot (or an absolute path). Just to note that this is obviously very much dependant on the directory structure of your website, so you may not be able to simply 'add a forward slash'.

Also, the single (or double) quotes around the path/filename are very much optional. I would tend to avoid them, unless you have some strange characters in your filenames (but then they are to be avoided anyway).

div#container{position:relative;text-align:left;background: #RGB url('images/border.gif') repeat-y 0 0}

You're not specifying a background-color for your #container element. It is always good practise to set a colour as well as an image for the background, incase the image doesn't show - the user may be browsing with images disabled?!

div#navigation h1{color:#FFFFFF;margin:0} 
div#content{position:relative;left:180px;padding:10px;background: #FFFFFF url('images/shadow.gif') repeat-y 738px 0px;
border-left-style:solid;border-left-width:1px}

You have the same foreground and background colours set in a few places. This may be perfectly OK, depending on your mark-up, but what if that 'shadow.gif' doesn't show?!

mooperlee

3:40 pm on May 15, 2007 (gmt 0)

10+ Year Member



Thanks very much for the replies.

Robin - thanks for those tips, I'll have a look at making those changes, and they all seem easy to understand.

Penders - the gif files which are coded as background images are, first of all, badly named, sorry about that.

I have now changed border.gif to fauxshadow.gif - it's not a background image for the whole container area, it's just a rectangle of colour to match my lefthand column, and make it appear as if the column always matches the height of the right-hand column. The coding should be correct cause I followed the instructions at A List Apart. Hopefully I wouldn't need a background colour instruction, because white would be the default?

The other image, shadow.gif, I am less certain of in terms of whether it is the best way to do things...Again, it's not a backround for the whole "content" area, in fact it's just a one-pixel width vertical line which is repeated down the page to provide a right-hand border line for my content area.

This is becase when I tried used the border-right-width: 1px command on the content div, it added a border fine, but it was pushed one pixel to the right...couldn't figure out why so I've used the image instead...any ideas as to why the border would show up one pixel too far to the right?

Phaaze

6:14 pm on May 15, 2007 (gmt 0)

10+ Year Member



mooperlee: The border issue - The reason is it pushed 1 pixel to the right is because a border goes on the outside of the div and not the inside, you'd have to decrease the width by 1px in order to get the border where you want...

mooperlee

8:51 pm on May 15, 2007 (gmt 0)

10+ Year Member



Thanks Phaaze! I've changed it now and all it took was deleting a pixel off the width, and voila! Much better than my convoluted way.