Style Sheets
  Home arrow Style Sheets arrow Page 5 - Learn CSS, Selectors, part 2
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, Selectors, part 2
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 14
    2005-06-13

    Table of Contents:
  • Learn CSS, Selectors, part 2
  • The Attribute Selector
  • Specific-Value Attribute Selector
  • The Specific-Values Attribute Selector
  • The Begin With Specific-Value Attribute Selector
  • The End With Specific-Value Attribute Selector
  • The Contain-Value Attribute Selector

  • 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, Selectors, part 2 - The Begin With Specific-Value Attribute Selector


    (Page 5 of 7 )

    Introduced by the CSS 3 Specifications (at this link: http://www.w3.org/TR/css3-selectors/#attribute-selectors), the begin with specific-value attribute selector applies the rule if the attribute's value begins with a specific string. It can be very handy. Suppose we need all the links to external websites to have a red background and white text colors, and the internal website links (those links to another web page within the website) will have a greenyellow background and blue text color. We can use the syntax of the begin with specific-value attribute selector to check whether the href attribute of the anchor element begins with "http://www." Let's take a look at the example and the syntax:

    a
    {
    background-color: greenyellow;
    color: blue;
    }
    a[href^="http://www"]
    {
    background-color: red;
    color: white;
    }
    p[lang|="en"]
    {
    color: blue;
    }
     

    Here's the HTML code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <link rel="stylesheet" href="Selectors.css" type="text/css">
    <title>CSS Selectors</title>
    </head>
    <body>
    <p>
    <a href="Home.html">Home</a>
    </p>
    <p lang="en-us">You can use CSS with markup languages like HTML, XHTML and XML. All
    those markup languages and also CSS has Specifications as the <a
    href="http://www.w3.org">W3C website</a>
    </p>
    <p>The <a href="http://www.w3.org" target="_blank">W3C website </a>
    contains specifications for web standards and it's
    very useful for web designers, developers and software architectures to
    navigate this website. For example, you have the CSS 2.1 Specifications
    and the XHTML 1.0 Specifications discussing everything from A to Z about
    the technology
    </p>
    </body>
    </html>

    And here is the result: 
     

    As you can see, we have two styles for anchor elements inside the Web page. I have added another anchor to the Web page to take us to the home page of the website. Because the href attribute doesn't begin with the string "http://www" it has been colored blue with the greenyellow background. On the other hand, the W3C website links do begin with "http://www" and that's why they have the other style.

    Here I want to make a side note on using two styles in this way. When we discuss cascade and inheritance you will grasp the concept of overriding certain styles. Although the W3C website is an anchor element and it must have the greenyellow background with a blue text, it has been overridden with the more specific attribute selector.

    The syntax for this selector is simple. Just precede the equal sign with the ^ symbol and type the string that the anchor's href attribute will begin with on the right of the equal sign like this:   a[href^="http://www"]

    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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek