Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How much smaller could this page be if it used CSS?

How much smaller could this page be if it used CSS?
Thread Tools
Scotttheking
Moderator Emeritus
Join Date: Dec 2000
Location: College Park, MD
Status: Offline
Reply With Quote
Dec 10, 2004, 03:17 AM
 
http://teamstats.macnn.com/fold/stats.php?page=s1
Go to that page and look at the html.
If the code were changed so that it used CSS, what kind of size savings could be expected?

--Scott
My website
Help me pay for college. Click for more info.
     
Simon Mundy
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Dec 10, 2004, 06:22 AM
 
Originally posted by Scotttheking:
http://teamstats.macnn.com/fold/stats.php?page=s1
Go to that page and look at the html.
If the code were changed so that it used CSS, what kind of size savings could be expected?

--Scott
Probably about half? You'd still use a table for your results, as it's tabular data. But you could certainly be rid of that font rubbish and reorganising the structure of the page. I'd also consider removing all the hard-coded Javascript and adding that via some DOM scripting.

1/2 a day - 1 day's work with a cool beer at the end of it. Or two.
Computer thez nohhh...
     
Phil Sherry
Dedicated MacNNer
Join Date: Nov 2004
Location: Stockholm, Sweden
Status: Offline
Reply With Quote
Dec 10, 2004, 08:10 AM
 
Originally posted by Simon Mundy:
1/2 a day - 1 day's work with a cool beer at the end of it. Or two.
Or three.
     
Millennium
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Dec 10, 2004, 09:17 AM
 
Two days, if you count the re-scripting.

Also keep inmind that the CSS is likely to be cached by a user's browser, so while there will be some savings on the first download there will be even better savings after that.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Zim
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Dec 10, 2004, 10:18 AM
 
Originally posted by Simon Mundy:
... I'd also consider removing all the hard-coded Javascript and adding that via some DOM scripting.
I'm looking at CSS for some redesign myself, and figure that's just a matter of reading and stumbling thru it, but I'm unfamiliar with what you mean by the last part...? (like I need something else to go off and learn )

Thanks,
Mike
     
Simon Mundy
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Dec 10, 2004, 07:29 PM
 
Originally posted by Zim:
I'm looking at CSS for some redesign myself, and figure that's just a matter of reading and stumbling thru it, but I'm unfamiliar with what you mean by the last part...? (like I need something else to go off and learn )

Thanks,
Mike
Hardcoding the Javascript into the HTML is counter-productive. If Javascript is disabled, it's unused and takes up space. If Javascript is enabled, then why not use it to add the interactivity by itself? E.g. for a mouseover event on a rollover, you could use Javascript to locate the rollover image, then apply a mouseover and mouseout event dynamically. It is not only space-saving, it's more reliable (you can make pretty reasonable assumptions that if it is able to create these events itself, it's probably capable of other stuff) and it's also very WAI friendly.

Our old friend www.alistapart.com has a whole heap of stuff about this with practical examples that may help you get started.

Cheers
Computer thez nohhh...
     
Zim
Senior User
Join Date: Apr 2001
Location: Cary, NC
Status: Offline
Reply With Quote
Dec 11, 2004, 10:08 AM
 
Originally posted by Simon Mundy:
Hardcoding the Javascript into the HTML is counter-productive. If Javascript is disabled, it's unused and takes up space. If Javascript is enabled, then why not use it to add the interactivity by itself? E.g. for a mouseover event on a rollover, you could use Javascript to locate the rollover image, then apply a mouseover and mouseout event dynamically. It is not only space-saving, it's more reliable (you can make pretty reasonable assumptions that if it is able to create these events itself, it's probably capable of other stuff) and it's also very WAI friendly.

Our old friend www.alistapart.com has a whole heap of stuff about this with practical examples that may help you get started.

Cheers
Thanks, I'll take a look.

Cheers,
Mike
     
Scotttheking  (op)
Moderator Emeritus
Join Date: Dec 2000
Location: College Park, MD
Status: Offline
Reply With Quote
Dec 28, 2004, 02:23 AM
 
Originally posted by Simon Mundy:
Probably about half? You'd still use a table for your results, as it's tabular data. But you could certainly be rid of that font rubbish and reorganising the structure of the page.
Thanks!
Could you or someone else explain how that would work? As someone who doesn't understand CSS, I don't get how exactly it would work. The example doesn't have to be code, just an explanation, although if showing some code works, I'm all for that.

--Scott
My website
Help me pay for college. Click for more info.
     
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Dec 28, 2004, 10:53 AM
 
Originally posted by Scotttheking:
Thanks!
Could you or someone else explain how that would work? As someone who doesn't understand CSS, I don't get how exactly it would work. The example doesn't have to be code, just an explanation, although if showing some code works, I'm all for that.

--Scott
I just ran it through HTML Tidy and told it to clean everything up and I got this. It's not really the best way to do things in a lot of areas but it can just give you something to look at and see how it got rid of font tags and cleaned some things up.

This is the super condensed version of CSS: Essentially, the HTML of a site remains essentially the same; for a good CSS+XHTML page, the HTML should basically be devoid of any style. That means no font tags, td color attributes etc... Taking care of the (X)HTML part of the page is easy; just write everything as simply as possible, removing any extraneous tags or attributes. For instance, it seems that the individual table rows are the most affected:

Code:
<TR BGCOLOR="#FF5050"><TD ALIGN="CENTER" NOWRAP><FONT FACE="Geneva"> <a href="stats.php?page=p1&UID=334">1</a></FONT> </TD><TD ALIGN="CENTER" NOWRAP><a href="http://vspx27.stanford.edu/cgi-bin/main.py?qtype=userpage&teamnum=16&username=OneMacGuy"> <FONT FACE="Geneva" COLOR="#000000">OneMacGuy</FONT></a></TD> <TD ALIGN="RIGHT" NOWRAP><FONT FACE="Geneva">803,776.0</FONT></TD><TD ALIGN="RIGHT" NOWRAP><FONT FACE="Geneva">2,824.29</FONT> </TD><TD ALIGN="CENTER" NOWRAP><FONT FACE="Geneva">&nbsp;</FONT> </TD></TR>
All of that code is rather excessive once you realize that you only have 5 cells and 4 pieces of text. Removing all the extraneous tags and attributes leaves:

Code:
<tr><td><a href="stats.php?page=p1&UID=334">1</a></td> <td><a href="http://vspx27.stanford.edu/cgi-bin/main.py?qtype=userpage&teamnum=16&username=OneMacGuy">OneMacGuy</a></td> <td> 803,776.0 </td><td>2,824.29</td><td></td></tr>
(I broke up both examples with returns as not to overly stretch the thread's layout)

There you have the absolute minimum amount of good code needed to display the information. This is what CSS can build upon. Basically, you want to style certain parts of your page. You want one particular box a certain color, with a certain font style. You want all of your headers to be 18px tall. You want all of your table cells to have their texts centered... but only the table cells in a specific table, in your case the statistics table. So, how do you do that? Basically, you want to specifically target, or select individual parts of your page. The selecting process is done with, conveniently enough, selectors. There a few types of selectors, but the most common ones are the HTML tag, class, and ID selectors. For example:

Code:
td { text-align: center; }
What that does is target, or select all of your tds and then apply the style information within the curly braces. Let's say that you want to target one part of your page, in your case, the statistics table. Well within the context of a good (X)HTML page, there is nothing to differentiate that table from any other table. So you need to set it apart from the others within the page. You can do this with either a class or an ID. They both identify specific parts of a page (all the summary paragraphs, for example, as opposed to all the paragraphs). They both do similar things, but the basic distinction is that if you only have one item per page that you want to target/select, then use an ID, as in giving it a unique ID. If, say, you want to set apart individual types of paragraphs, where multiple paragraphs may exist on one page� use a class. I hope this isn't all too confusing, but when you actually do it, it's not too bad. So, you would want to uniquely identify your statistics table within your page:

Code:
<table id="statistics">
You can give it any ID you want, but make sure it's at least alphanumeric and doesn't start with a number. Now that you've set apart the table, you can select and style it with CSS:

Code:
#statistics { font-family: Geneva, sans-serif; }
"#statistics" is just like "td" except that the "#" signifies that the browser's rendering engine should select anything that's ID'd with "statistics". If you're using a class (in which case the html would be "class=") then instead of a hash mark/pound/whatever you'd use a period� .header

Note that you should try to start as high up as possible in the document hierarchy (tag-wise: body > table > tr > td) and find what applies to everything lower down in the hierarchy, or at least the majority� you can uniquely ID anything that doesn't follow the norm. So starting with "body", I can see that your tables, trs, tds, paragraphs etc... all use the font Geneva, so I would do:

Code:
body { font-family: Geneva, sans-serif; }
Basically everything down the hierarchal line gets "Geneva" as its font. This is called inheritance. Not everything gets inherited however; for instance, if you set a margin on your body, not everything is going to get the same margin on the way down. Whether or not something will be inherited down the line is different for every property but it usually makes sense when it does� text based properties are usually passed down: font color, family, style, decoration etc...

Anyways (I'm cutting this slightly short, but hopefully you have a vague idea of how this all works), using what you know, you can now do something like this for your statistics table:

Code:
<tr class="red"><td><a href="stats.php?page=p1&UID=334">1</a></td><td> <a href="http://vspx27.stanford.edu/cgi-bin/main.py?qtype=userpage&teamnum=16&username=OneMacGuy">OneMacGuy</a> </td><td> 803,776.0 </td><td>2,824.29</td><td></td></tr>
Code:
#statistics .red { background: red }
Another thing I failed to mention is that if you combine multiple selectors, you get what are called descendant selectors. What that last bit of code basically says is "select all the html elements that are classified under 'red' and are inside the one html element whose unique ID is 'statistics'". It works from the left to right on the "containment level" if that makes any more sense. Then on all your red table rows, you'll want to mark them up like so:

Code:
<tr class="red">. . .</tr>
Another thing to keep in mind is that a big part of XHTML+CSS is making meaningful class and ID names. So if red means important, use "class='important'" instead.It will always mean important no matter what design you decide to use later, but it may not always be red. Perhaps you may later opt for a grayscale design, with dark gray being more important and light gray less so.

As you might have guessed, you'll want to do the same thing for all the other colors. You also might have realized that now that you have all of your style information in one place, you can edit it in that one place and have the entire page change� before you'd have to edit each individual line. In your particular case, it looks like your dynamically generating the page, so it probably isn't as much of a problem, but it's still good thing to have nonetheless.

Another thing I left out, since I wasn't exactly sure how much passing knowledge of CSS you have� any time I reference CSS, it should be put within a style block in your head:

Code:
<head> <style type="text/css"> [CSS goes here] </style> </head>
Alternatively, you can stick all your CSS code in one file and reference it on the page (also put this in the head):

Code:
<link href="styles.css" rel="stylesheet" type="text/css" />
Which is better if you're using the CSS on multiple pages, which might be an eventual goal, but for now it won't hurt to simply keep the CSS within the page.

I hope this helps� realize that I probably could have rewritten the page in the same amount of time that it took me to write this post, but you just seemed so keen on figuring out how to do it yourself that I took the time to try and explain it all out There are a lot of individual things to learn about CSS (for instance, you should separate all your style attributes with a semicolon, if you didn't already known� color: red; font-size: 12px;), but if you have a good understanding of how CSS works in tandem with (X)HTML, then those should come a lot easier. If you want to read through a good reference guide, check out the WestCiv Tutorial. I usually use it as a reference, but I initially read through it; it's a good way to get up to speed with all the different things you can do with CSS>

Have fun
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:37 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,