Style Sheets
  Home arrow Style Sheets arrow Page 2 - 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 - The :link and :visited Pseudo Classes


    (Page 2 of 5 )

    The :link pseudo class applies styling rules only to the unvisited hyperlinks, and the :visited Pseudo Class applies to the visited hyperlinks. So what's the difference between using the element selector a to apply the style and using the pseudo class selector :link? Actually there's a big difference. Using the :link pseudo class applies the style only to those <a> elements that have the href attribute and not document links (those <a> elements with the name attribute). On the other hand, using the element selector a applies the style to all <a> elements.

    The :link and :visited pseudo classes are supported by IE 5.5, 6 and Mozilla 1.7 and Opera 7.5 too. Let's take a look at an example of using the :link pseudo class. We need our hyperlinks to have a white text with a YellowGreen background and Arial font with a size of .8em.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <link rel="stylesheet" href="P.css" type="text/css">
        <title>CSS Pseudo Classes</title>
      </head>
      <body>
        <table>
          <tr> 
            <td>
              <a href="http://www.devarticles.com">devarticles Website</a>
            </td>
          </tr>
          <tr>
            <td>
              <a href="http://www.aspfree.com">aspfree Website</a>
            </td>  
          </tr>
          <tr>
            <td>
              <a href="http://www.devshed.com">devshed Website</a> 
            </td>
          </tr>
          <tr>
            <td>
              <a href="http://www.seochat.com">SEOchat Website</a>
            </td>
          </tr> 
        </table>
      </body>
    </html>

    Here's the CSS code:

    a:link
    {
      background-color: YellowGreen;
      color: white;
      font-family: Arial;
      font-size: .8em;
    }

     

    As you can see, three out of four hyperlinks have been styled; why? On my machine I have visited only www.devarticles.com. I didn't visit the other websites. What happened here is that the browser has used the default style for the visited websites and our style for the unvisited websites. I will delete the history and see what the result will be.

    Now these hyperlinks are unvisited. Let's add some code to differentiate the visited links. We need the visited links to have the same style as the unvisited links, except for the text color, which will be black. Add the following CSS rule to the CSS file:

    a:visited
    {
      background-color: YellowGreen;
      color: black;
      font-family: Arial;
      font-size: .8em;
    }

    Now open the Web page and visit the first two websites; you will have the following result. Before we leave this section you need to know that the order in which you write the pseudo class styles in the CSS file is very important. We will discuss this in the article about Cascading.

    More Style Sheets Articles
    More By Michael Youssef


     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







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