Go Back   SitePoint Forums > Forum Index > Design Your Site > Web Page Design > CSS
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Mar 3, 2004, 05:26   #1
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
Please use CSS Efficiently

I just wanted to post something on my mind.

For those of you who are new to CSS, its very common to think its a great method of styling text. I have stumbled across several sites that have every <p> element with a class or ID.

I have even come across sites that style the <font> tags. Isn't that weird? There is nothing more annoying than having to clean up a site and seeing

<font class="blah"> or <font style="blah: 0px;">

I know these are newbie mistakes, but learn as much as you can and try to cut down on the amount of markup you will need. If you know your paragraphs in a particular page / site are going to look / act the same, then by all means, style just the <p> element in your stylesheet to save yourself the time and energy of styling every tag.

body p {
Font-Face value: value ;
font-size: value ;
margin: value ;
padding: value ;
}

You honestly only need to apply classes or ID's on elements that require special attention.

For any css experts, correct me if I am wrong or chime in if you want to add anything.

Bryan
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 05:34   #2
xhtmlcoder
Robert Wellock
bronze trophy
 
xhtmlcoder's Avatar
 
Join Date: Apr 2002
Location: A Maze of Twisty Little Passages
Posts: 2,384
Styling a <font> element with a class that's a fairly novel approach.
__________________
};-) http://www.xhtmlcoder.com/
xhtmlcoder is offline   Reply With Quote
Old Mar 3, 2004, 05:41   #3
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
I'm telling you, i have seen it and I have deleted it
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 06:11   #4
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 32,859
what you describe, bryan, is called "classitis"

see http://lists.evolt.org/archive/Week-...21/145459.html and http://developer.apple.com/internet/...estwebdev.html
__________________
r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
"giving out my real stuffs"
r937 is online now   Reply With Quote
Old Mar 3, 2004, 06:44   #5
Paul O'B
CSS Advisor
silver trophybronze trophy
SitePoint Award Recipient
 
Paul O'B's Avatar
 
Join Date: Jan 2003
Location: Hampshire UK
Posts: 29,644
classitis and divitis - I think we need to be innoculated against it
Paul O'B is offline   Reply With Quote
Old Mar 3, 2004, 08:28   #6
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,423
Quote:
Originally Posted by xhtmlcoder
Styling a <font> element with a class that's a fairly novel approach.
I've seen it done many a time.

Another tip: Please name your classes/IDs based on the content contained within, not by what style you're applying to it.

Bad:
HTML Code:
<span class="text-20-bold-red">NOTE:</span>
Code:
.text-20-bold-red {
  font-family: Verdana, Helvetica, sans-serif;
  font-size: 20px;
  font-weight: bold;
  color: #c00;
}
Good:
HTML Code:
<strong class="must-read">NOTE:</strong>
Code:
.must-read {
  font: bold 20px Verdana, Helvetica, sans-serif;
  color: #c00;
}

Last edited by vgarcia; Mar 3, 2004 at 09:54..
vgarcia is offline   Reply With Quote
Old Mar 3, 2004, 09:47   #7
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
what about

<span class="italic">

I just got done using that one . However, its with the intentions that anything in the site you want bold and italic, give it a class of that
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 09:48   #8
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 32,859
<sigh />

oh, vinnie

your good/bad analogy is, um, weak

instead of styling SPAN, you should be styling EM

what is importance, if not a form of emphasis?

and the choice of class name "important" is unfortunate

i was expecting an example of !important

maybe i am too much of a structural purist

but to classitis and divitis i must also add spanitis
__________________
r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
"giving out my real stuffs"
r937 is online now   Reply With Quote
Old Mar 3, 2004, 09:48   #9
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 32,859
bryan!! while i am replying, you go and suggest something even worse!!
__________________
r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
"giving out my real stuffs"
r937 is online now   Reply With Quote
Old Mar 3, 2004, 09:50   #10
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,423
Quote:
Originally Posted by r937
<sigh />

oh, vinnie

your good/bad analogy is, um, weak

instead of styling SPAN, you should be styling EM

what is importance, if not a form of emphasis?

and the choice of class name "important" is unfortunate

i was expecting an example of !important

maybe i am too much of a structural purist

but to classitis and divitis i must also add spanitis
Edited.
Off Topic:

I think it deserves strong emphasis too
vgarcia is offline   Reply With Quote
Old Mar 3, 2004, 09:51   #11
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,423
Quote:
Originally Posted by jag5311
what about

<span class="italic">

I just got done using that one . However, its with the intentions that anything in the site you want bold and italic, give it a class of that
Why not just use <i> or <b> then?
vgarcia is offline   Reply With Quote
Old Mar 3, 2004, 09:55   #12
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
because I thought you are suppose to stray away from using actual HTML to do anything presentational. At least I have come across a few articles saying its better to create a style for elements like that. I HAVE been using those inside my html, but just until about 1 hour ago did I create something instead .
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 09:58   #13
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,423
Quote:
Originally Posted by jag5311
because I thought you are suppose to stray away from using actual HTML to do anything presentational.
What type of content are you styling? If it's something specific you may be better off styling an HTML element other than <span>; otherwise, if the bold/italic is there for emphasis, strong and em should be used.
vgarcia is offline   Reply With Quote
Old Mar 3, 2004, 10:01   #14
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
Ok, so you style <em> because of the importance factor, but what about if you have some other elements that require importance (I mean like bold or something different the the normal body text, not !important). So

Regular importance (Rudy's analogy)

<em>This is important</em>

but then down the page you have something else, but you want it to be a little bigger and a different color, do you create a style for

em.otherimportant

or do you create one for a span?

so in this paragraph,

Code:
 While certain words are important, <em>this word is pretty important</em>, but after reading for a while you will come across <em class="?">MORE IMPORTANT</em> words then earlier.
So structurally speaking, do you just create a span for that 2nd word, or a class for that particular em?
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 10:01   #15
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 32,859
"why not just use <i> or <b> then?"

oh, no, please, not that discussion again!

these tags are not deprecated

there are situations where I and B are appropriate, instead of EM and STRONG

and let's not forget <strong><em>really really strong emphasis</em></strong>

oh, and bryan, think about what you just said -- "stray away from using actual HTML to do anything presentational"

what's presentational about DIV? SPAN?

as we say in canada, "duh, eh"

__________________
r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
"giving out my real stuffs"
r937 is online now   Reply With Quote
Old Mar 3, 2004, 10:07   #16
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
I don't appreciate your smart as.s remarks j/k

Let me clarify my statement

----> <div> tags, IMO, are not necessarily presentational tags, rather they are containers for content.

----> <b> or <i>, IMO, are presentational tags, because they style the content within the containers.

When I said HTML, obviously I was refering to the fact that <b><i> are HTML tags that happen to have 1 purpose, providing presentation to specific segments of content. That is there only purpose.

To be honest now, I don't even know if I clarified my original statement
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 10:24   #17
vgarcia
☆★☆★
silver trophy
 
vgarcia's Avatar
 
Join Date: Jan 2002
Location: in transition
Posts: 21,423
If you want more emphasis than <em>, use <strong>. If you need even more emphasis than that, then you should relax because you're probably too high-strung .
vgarcia is offline   Reply With Quote
Old Mar 3, 2004, 10:32   #18
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
, well I was just refering to the structural aspect of it, so I guess I will use <em> and strong .
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 11:19   #19
megamanXplosion
SitePoint Wizard
 
megamanXplosion's Avatar
 
Join Date: Jan 2004
Location: Kentucky, USA
Posts: 1,091
Just because an element contains a built-in style doesn't mean that CSS replaces it. The EM and STRONG tags are a great example. Screen-readers will read off emphasized (EM) words differently than normal words that would be within a SPAN or DIV, because it is supposed to be emphasized.

From my understanding, EM'd words will be said with a higher-pitch than normal words, and STRONG'd words will be said a little bit louder than normal text. Take these two examples...


Code:
<strong>Dirty cheater!</strong>
That would be like a small yell within a screen-reader.

Code:
I can't believe it was <em>you</em>!
This would be read off like normal text, except that "you" would be read off in a higher pitch. Those, emphasizing the word "you".




Of course, I am in no way, shape or form, an accessibility expert so this post should be taken with a grain of salt.
megamanXplosion is offline   Reply With Quote
Old Mar 3, 2004, 12:29   #20
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
interesting. Thanks for that Mega. Now that makes perfect sense.
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 15:36   #21
emmzee
Unauthorized Web Theologian
 
emmzee's Avatar
 
Join Date: Jan 2004
Location: Mississauga, Ontario, Canada
Posts: 736
I'm wondering why this:

Code:
.text-20-bold-red {
  font-family: Verdana, Helvetica, sans-serif;
  font-size: 20px;
  font-weight: bold;
  color: #c00;
}
Is less preferable to this:

Code:
.must-read {
  font: bold 20px Verdana, Helvetica, sans-serif;
  color: #c00;
}
Besides the name, I mean. Is it bad style to have seperate identifiers for things, like in this example using font-family, font-... instead of just using font? I always have used separate lines ... other than I suppose bandwidth issues if you have tons of these things or get a huge amount of traffic?
__________________
Darren Hewer
New site: Simpsons Triva Quiz
DOS Games, Free Web Games, Why Faith Blog
emmzee is offline   Reply With Quote
Old Mar 3, 2004, 15:58   #22
r937
SQL Consultant
silver trophybronze trophy
SitePoint Award Recipient
 
r937's Avatar
 
Join Date: Jul 2002
Location: Toronto, Canada
Posts: 32,859
shorthand forms are better because they're shorter

except when they are interpreted differently by different browsers

see http://home.no.net/junjun/html/shorthand.html
__________________
r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
"giving out my real stuffs"
r937 is online now   Reply With Quote
Old Mar 3, 2004, 15:59   #23
jag5311
SitePoint Wizard
 
jag5311's Avatar
 
Join Date: Jan 2003
Location: Somewhere in Indiana
Posts: 3,084
Your right on the money, simply because it uses less lines which means less bandwidth. I use dreamweaver and sometimes its so much easier to hop up to Design and then css and pick what you want versus typing it out, though typing it out should probably be the way to go



Quote:
Originally Posted by emmzee
I'm wondering why this:

Code:
.text-20-bold-red {
font-family: Verdana, Helvetica, sans-serif;
font-size: 20px;
font-weight: bold;
color: #c00;
}
Is less preferable to this:

Code:
.must-read {
font: bold 20px Verdana, Helvetica, sans-serif;
color: #c00;
}
Besides the name, I mean. Is it bad style to have seperate identifiers for things, like in this example using font-family, font-... instead of just using font? I always have used separate lines ... other than I suppose bandwidth issues if you have tons of these things or get a huge amount of traffic?
__________________
Major Championships - Golf Blog







jag5311 is offline   Reply With Quote
Old Mar 3, 2004, 16:11   #24
megamanXplosion
SitePoint Wizard
 
megamanXplosion's Avatar
 
Join Date: Jan 2004
Location: Kentucky, USA
Posts: 1,091
The change of the name is good because it prevents you from having to rename classes/IDs all throughout your HTML if you want to change the style.

The second one is good because it is compressed into a shorthand rule. Thus, saving bandwidth. Take this class for example...

Code:
	.note {
		background-color: #EEE;
		border: 1px Solid #000000;
		border-top-width: 6px;
		border-right-width: 3px;
		border-bottom-width: 2px;
		padding-top: 5px;
		padding-right: 20px;
		padding-bottom: 40px;
		padding-left: 20px;
		margin-top: 10px;
		margin-right: 0px;
		margin-bottom: 40px;
		margin-left: 0px;
		font-style: Italic;
		font-weight: Bolder;
		font-size: 9pt;
		line-height: 130%;
		font-family: Verdana, Arial, Helvetica, Sans-Serif;
	}
can be compressed down to the below which just little effort...

Code:
	.note {
		background-color: #EEE;
		border-style: Solid;
		border-color: #000;
		border-width: 6px 3px 2px 1px;
		padding: 5px 20px 40px 20px;
		margin: 10px 0 40px 0;
		font: Italic Bolder 9pt/130% Verdana, Arial, Helvetica, Sans-Serif;
	}


Just a couple of optimizing tips...
  • The shorthand rules that deal with dimensions (border, margin, padding) can be compressed to one statement.
    • Rule: Top Right Bottom Left
  • The font properties can be compressed into one statement.
    • font: Style Weight Size/Line-Height Font-Names
  • When using dimensions and you set a side to 0 with a measurement unit at the end, you can ommit the unit, because 0 is 0, regardless of measurement.
    • 0px = 0
    • 0em = 0
  • Color values can sometimes be compressed. Here are a couple of ways...
    • rgb(0,255,0) = #00FF00 (RGB converted to 6-digit hex equivalent)
    • #00FF00 = #0F0 (6-digit hex is converted to 3-digit. If the color is like [RR & GG & BB], then it can be compressed to [R & G & B].)
megamanXplosion is offline   Reply With Quote
Old Mar 3, 2004, 17:17   #25
Percept
webdesign
 
Percept's Avatar
 
Join Date: Jan 2003
Location: Belgium
Posts: 398
Quote:
Originally Posted by r937
"why not just use <i> or <b> then?"

oh, no, please, not that discussion again!

these tags are not deprecated

there are situations where I and B are appropriate, instead of EM and STRONG

and let's not forget <strong><em>really really strong emphasis</em></strong>

oh, and bryan, think about what you just said -- "stray away from using actual HTML to do anything presentational"

what's presentational about DIV? SPAN?

as we say in canada, "duh, eh"

Soooo <i> & <b> are not depricated ? So why is everyone using <em> and <strong> then since <i> & <b> are shorter. Is there actually a difference between <i> & <em> and <b> & <strong> ?
__________________
Percept - Desk02 webdesign
Percept is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting 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

 
Forum Jump


All times are GMT -7. The time now is 09:23.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved