Home arrow Style Sheets arrow Page 3 - The Advantages of Style Sheets
STYLE SHEETS

The Advantages of Style Sheets


Style sheets have become ever more popular each year as designers realize that whole web sites can be customized without too much fine editing. They allow properties for the whole site to be set, such as page color, link color, margins, text size, and much more. All of these can be keyed into a single file or in the main body of the code.

Author Info:
By: Stephen Davies
Rating: 3 stars3 stars3 stars3 stars3 stars / 6
August 07, 2007
TABLE OF CONTENTS:
  1. · The Advantages of Style Sheets
  2. · Inline and External Styles
  3. · The CLASS and ID tags
  4. · Final Working Examples

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
The Advantages of Style Sheets - The CLASS and ID tags
(Page 3 of 4 )

As shown briefly earlier, style sheet properties can be specified according to the tag -- P, H1, FONT, etc. This is the power of style sheets in styling the page as a seamless process. We can apply a variety of different classes to various tags. Using the internal style sheet example:

<HEAD>
 
<TITLE>Change the paragraph colour and size</TITLE>
 
<STYLE TYPE="text/css">
   
P.colorchoice1 { font-size: 3; color: blue; }
   
P.colorchoice2 { font-size: 3; color: red; }
 
</STYLE>
</HEAD>

This is the same as the example on the first page of this article except that it can set two different colors for the <P> tag lines in the HTML code. They keep the font type and size the same but apply two different colors -- blue and red. Any different style can be applied to the same tag as shown above. Remember that hex values can be applied here too; for example, red would be #990000.

On the first page, it was briefly explained how to apply class names. For the example above, the P tag can be given the two color properties like this:

<p class="colorchoice1">
  The text is blue
</p><br>
<p class="colorchoice2">
  The text is red
</p>

The resulting displayed text would be:

The text is blue

The text is red

You can also use the ID selector to define any styles for the HTML code. This is done via the # symbol. Looking at the example above:

<HEAD>
  <TITLE>Change the paragraph colour and size</TITLE>
  <STYLE TYPE="text/css">
   
p#colorchoice1 { font-size: 3; color: blue; }
   
p#colorchoice2 { font-size: 3; color: red; }
 
</STYLE>
</HEAD>

The HTML display will show the page text that uses the ID of colorchoice1 or colorchoice2. So in the main body of the HTML code:

<p id="colorchoice1">
  The text is blue
</p><br>
<p id="colorchoice2">
  The text is red
</p>

The ID selector can be left as a single property and used for any of the HTML tags again simply by omitting the tag specification:

#blue {color: blue}


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials