| An Introduction to CSS |
pages (2): 1 [2] |
|
|
Section 3: IDs
IDs work in similar ways to classes, except that they can only be used once (whereas classes can be used multiple times). For this reason, you should stick with classes for most formatting, and only use IDs for unique properties. Another reason they exist is to allow you to incorporate Style Sheet models into JavaScript or DHTML. If you want to give IDs a whirl, here's how to use them:
The CSS:
|
#bigfont{ font-family:Arial, Helvetica, sans-serif; font-size:40px; }
| The HTML:
|
<font id="bigfont">This is big text.</font>
|
The above example is valid coding, while this next example is not.
The CSS:
|
#bigfont{ font-family:Arial, Helvetica, sans-serif; font-size:40px; }
| The HTML:
|
<td id="bigfont"> <font id="bigfont">This is big text inside a <td> with the
same class applied.</font> </td>
|
Section 4:
Linking to External CSS Finally we get to the end. The last thing
to know is how to actually use the stylesheet. Once you compile together all of
your CSS into one file, save it with a .css extension.
Now go into your HTML document and add this line within your <head> tags:
<link rel="stylesheet" type="text/css" href="file.css" media="all" title="Your Title"/>
|
Replace 'yourfile.css' with the path to the CSS file
and 'Your Title' with whatever you want to call your stylesheet.
And thats it! For more detail on attributes and settings, try
accessing a reference site such as
W3Schools. Enjoy your newfound skills!
- Tutorial written by Gus Mayo
| 
|
|
|
This is a good tutorial to get people's feet wet in CSS. I like the layout but would suggest splitting lines at the semi-colon. Having one style per line really helps readability.
I have one criticism though in the example you choose, namely bigfont. Though technically valid it goes against the whole CSS concept of separating semantics from style. A designer should ask themselves why they want a font bigger. Normally this is because it marks a section, chapter, or some other structural entity. In this case, use the appropriate header tags (H1, H2, H3...). That's what they are for!
This not only saves having to define your own class, but it provides consistent information for screen readers, search engines, and other non-visual browsers of your page.
I never use the HTML font tag. It's presence is generally a good indication that the design is wrong. |
Reply to this post |
--- View Entire Thread ---
|

|
|
 |
TrentonCS Author: ahstanford Posted: Nov 06th, 7:40pm Activity: 3 replies, 27 views
|  | Html 5 Author: ahstanford Posted: Nov 05th, 1:32pm Activity: 5 replies, 89 views
|  | What are your favorite websites? Author: ahstanford Posted: Nov 05th, 12:51am Activity: 0 replies, 47 views
|  | What do you do for a living? Author: ahstanford Posted: Nov 04th, 11:04pm Activity: 0 replies, 45 views
|  | What is your favorite Subway sandwich? Author: ahstanford Posted: Nov 04th, 11:02pm Activity: 4 replies, 88 views
|  | Windows 7 Author: ahstanford Posted: Nov 04th, 10:59pm Activity: 0 replies, 49 views
|  | Google Wave Author: ahstanford Posted: Nov 04th, 10:52pm Activity: 0 replies, 60 views
|  | University Project Author: Gjbphp Posted: Nov 03rd, 8:59pm Activity: 1 replies, 90 views
|  | Hello BioRust! Author: ahstanford Posted: Nov 02nd, 5:39pm Activity: 4 replies, 87 views
|  | Illustrator cs4 - Convert outlines/graphics to ... Author: izidrew Posted: Oct 29th, 3:48pm Activity: 3 replies, 259 views
|  | Hello BioRust!! Author: MOST Posted: Oct 29th, 12:52am Activity: 4 replies, 144 views
|  | Hey! newbie Author: prelimiting Posted: Oct 28th, 11:51pm Activity: 1 replies, 113 views
|  |
|
 |
 |
 |
 |
 |
| --- Site Resources --- |
| Total Tutorials: | 212 |
| Total Downloads: | 415 |
| Linkbase Links: | |
 |
|
 |
 |
|