Style Sheets
  Home arrow Style Sheets arrow Learn CSS: Pseudo Classes
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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

Learn CSS: Pseudo Classes
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 20
    2005-07-11

    Table of Contents:
  • Learn CSS: Pseudo Classes
  • The :link and :visited Pseudo Classes
  • The :hover Pseudo Class
  • The :active Pseudo Class
  • The :focus Pseudo Class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Learn CSS: Pseudo Classes


    (Page 1 of 5 )

    We met pseudo elements in the last article. In this article we will discuss pseudo classes, which give you the ability to apply certain styling rules on specific states of an element. In this part we discuss the following pseudo classes: :link, :visited, :hover, :active and :focus, :root, :first-child, and :last-child. Note that with CSS 3 there are many new pseudo classes. Not all of them are implemented, however, so I will discuss only the pseudo classes that have been implemented by the major browsers.

    Pseudo elements offer us the ability to apply styling rules on parts of the markup document that can't be expressed with markup elements, such as the first line or even the first letter of a paragraph. We saw this in the previous article of this series, "Learn CSS, part 7: Pseudo Elements." Pseudo classes are very similar to pseudo elements, but pseudo classes apply the styling rules to the element depending on some state.

    For example, there's a pseudo class called :hover which you can use to style an element (for example the <a> element) when the user hovers the mouse pointer over it. So in this example the style will be applied to the element if the state "hovering" occurs. The syntax for using pseudo classes is one colon (:) followed by the class name. In CSS 2 both pseudo elements and pseudo classes used the one colon syntax, but CSS 3 changed this behavior to differentiate between them.

    There's another way we can explain pseudo classes. Of course you can set the styles of the document links through the use of one rule (like a {color: white; background-color: black;}). Now can you set the style of the links that have been visited? No, you can't do that because you don't have any way to know what links the user has visited and then apply styles to them. With CSS pseudo classes you can apply styling rules to visited links through a pseudo class (:visited). This means that you apply certain styling rules depending on the state of the element (a visited link). So let's discuss our pseudo classes.

    More Style Sheets Articles
    More By Michael Youssef


     

    STYLE SHEETS ARTICLES

    - Building Rounded Corners with CSS3`s -webkit...
    - Using the Custom -moz-border-radius Property...
    - Using CSS3`s Border-Radius Property to Build...
    - Adding Semantic Meaning to Styled Code Block...
    - Styling Code blocks with CSS: Using pre HTML...
    - Building Rounded Corners with CSS3
    - Finishing a Casual Navigation Bar with CSS S...
    - Defining a Navigation Bar`s Hover State with...
    - Styling a Blog`s Links Bar with CSS Sprites
    - Creating an Artistic Blog Header with CSS Sp...
    - Defining the Active State of Menu Sections f...
    - Styling the Hover State of a CSS Sprite-Base...
    - Building CSS Sprite-Based Navigation Bars
    - Creating Framed Pictures with CSS
    - Using a CSS Shading Effect to Decorate Images







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek