Home arrow Style Sheets arrow Page 3 - CSS for the Newbie
STYLE SHEETS

CSS for the Newbie


Although style sheets have technically been around in one form or another since the 1970s, it wasn't until around 1996 that they truly became an official part of the web. And although they had a rocky start with browser support, today they are widely used and offer designers a simple way to define style rules for their web pages, saving them from having to type in colors, fonts, and other layout properties over and over again.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 6
February 25, 2008
TABLE OF CONTENTS:
  1. · CSS for the Newbie
  2. · Putting it all Together
  3. · Selectors...Unite!
  4. · Applying a Style to an Element with an Attribute
  5. · Doing It In Style

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
CSS for the Newbie - Selectors...Unite!
(Page 3 of 5 )

You can assign groups of selectors the same value in the following manner:


h1,h2,h3,h4,h5,h6

{

font-family: “Comic Sans”;

font-size: 12pt

color: red;

text-align: center

}

Now, every time we use any of the headers, the text will automatically have the font type of Comic Sans, have a font size of 12 points, be red in color, and aligned to the center of the page.

Assigning the Same HTML Element with a Different Value

Say you wanted to have an <h1> header tag with a certain default value. Every time you used that tag, it would have the attributes you defined. But what if every once in a while you wanted to insert an <h1> tag that had different attributes? Well you can do so by using the Class Selector. Here it is in code:


h1.weird {font-family:”Comic Sans”;color:red}

h1.notweird{font-family:Verdana;color:black}


The above would create two Class Selectors. If you typed h1.weird, it would apply the attributes you defined in that Selector. If you typed h1.notweird, it would apply the font as Verdana and the color as black.

This allows you more flexibility when designing your site.

You use the class attribute to apply it:


<h1 class=”weird”>

Here is a mighty header!

</h1>

<h1 class=”notweird”>

Here is an even mightier header!

</h1>

Say I wanted to add more than one class to my element. First, let's create a third element:


h1.weird {font-family:”Comic Sans”;color:red}

h1.notweird{font-family:Verdana;color:black}

h1.center{text-align:center}

Now to apply two of the classes:


<h1 class=”weird center”>

Here is a mighty header!

</h1>


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 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials