Style-Sheets
  Home arrow Style-Sheets arrow Page 3 - Understanding Style Sheets (Part 1)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE-SHEETS

Understanding Style Sheets (Part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 32
    2000-09-27


    Table of Contents:
  • Understanding Style Sheets (Part 1)
  • Into The Light
  • More Pseudo-Gibberish
  • The Colour Of My Eyes
  • Playing With Type
  • Adding A Little Style

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Understanding Style Sheets (Part 1) - More Pseudo-Gibberish
    ( Page 3 of 6 )

    Next on the basic concept list: inheritance, classes, pseudo-classes and contextual selectors. Let's take them one by one.

    Inheritance:Inheritance basically means that HTML elements which lack a specific style rule will inherit the style rules of the elements they are enclosed within. For example, consider this snippet of code:

    <HTML>
    <HEAD>
    <STYLE TYPE="text/css">
    B {color: red}
    </STYLE>

    </HEAD>

    <BODY>

    <B>
    Q.  How many <FONT SIZE="+1">psychiatrists</FONT> does it take to change a
    lightbulb?
    <P>
    A.  Only one, but the lighbulb has to want to change.
    </B>
    </BODY>
    </HTML>

    In this case, the <B> tag has a color defined in the style sheet, while the <FONT> tag doesn't have any style rule defined for it. Since the <FONT> tag is enclosed within the <B> tags, it inherits the style rule defined for the <B> tag - in this case, the colour red.


    Classes:CSS also allows you to group elements together in "classes" and apply a style rule to that class. For example,

    <HTML>
    <HEAD>
    <STYLE TYPE="text/css">
    .question {color: red}
    .answer {color: blue}
    </STYLE>

    </HEAD>

    <BODY>

    <P CLASS="question">
    Q.  How many psychiatrists does it take to change a lightbulb?
    <P CLASS="answer">
    A.  Only one, but the lighbulb has to <FONT CLASS="question">want</FONT> to
    change.

    </BODY>
    </HTML>

    In this case, we've defined two classes, "question" and "answer", with appropriate style rules for each (note the manner of their definition within the <STYLE> tags, and the period prefix). Next, we've invoked the appropriate style rules by adding the CLASS attribute to the HTML tags within the body of the document.All the text within tags which are marked as part of the class named "question" will appear in red, while all the text within the "answer" class will appear in blue.Thus, CSS gives you a simple and elegant way to group otherwise unrelated tags together, and apply a common style rule to them.

    Pseudo-classes:Unlike what the name suggests, these are actually pre-defined classes for certain HTML tags. The most well-known of these are the pseudo-classes defined for the anchor element A - it
    comes with the following pre-defined classes:A:link - refers to all
    hyperlinks within the document A:visited - refers to all visited hyperlinks within the document A:active - refers to the last hyperlink selected within the document A:hover - refers to the hyperlink your mouse pointer is currently hovering overBy using these pseudo-classes, it's possible to change the default colour of active, visited and unvisited hyperlinks within the document.

    Contextual selectors:Contextual selectors are a lot like conditional statements - the style declarations that follow them are invoked only when certain conditions are met. For example, suppose you'd like all bold italic text in your document to appear in blue Arial. Your contextual selector would look like this:

    <HEAD>
    <STYLE TYPE="text/css">
    B I {color: blue; font-family: Arial} /* this selector is for all
    bold+italic text */
    </STYLE>
    </HEAD>

    Go on, try it yourself. Do I look like I'm lying?



     
     
    >>> More Style-Sheets Articles          >>> More By icarus, (c) Melonfire
     

       

    STYLE-SHEETS ARTICLES

    - What is CSS?
    - The Power of CSS
    - Understanding Style Sheets (part 2)
    - Understanding Style Sheets (Part 1)





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT