Style Sheets
  Home arrow Style Sheets arrow Learn CSS: Introduction to Inheritance, Sp...
eWeek
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  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 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: Introduction to Inheritance, Specificity, and Cascade
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2005-07-18

    Table of Contents:
  • Learn CSS: Introduction to Inheritance, Specificity, and Cascade
  • The Style Tag
  • Importing Style Sheets
  • CSS Inheritance

  • 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
     
     
    Iron Speed
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Learn CSS: Introduction to Inheritance, Specificity, and Cascade
    (Page 1 of 4 )

    We are still discussing the basic concepts of CSS. In this article (and the next part) we will talk about how the structure of the CSS document can affect Web page design. Actually, there's something that I haven't discussed until now, which is what are the places that we can use to write styles and how it can affect the Web page. This is also related to the cascade, inheritance and specificity concepts which help you to understand how to structure your CSS document. This article is the ninth in a series covering CSS.

    Before we discuss the meaning of the CSS cascade and the related concepts, you need to know that there are places to write styles other than the .css file (this is essential for the following sections). You also need to understand that there is more than one type of CSS file that affects how Web pages will look. Let's take a look.

    Inline Styles

    Up to this point we have been applying CSS styles by using an external file (with the extension .css) and linking it to the HTML document with the help of the <link> element. In fact there are other places where you can write your CSS styles. As we will see (in the Cascade sections), writing styles in these places without knowledge of the cascade concept will produce unexpected results. That's why I begin this article with a discussion of these places.

    The first place to write styles is the HTML element itself using the Style attribute. You write your CSS declarations surrounded by double quotations, as in the following HTML document:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>CSS Structure</title>
      </head>
      <body style="font-family: Arial; font-size: 1.1em;">
        <div style="color: white; background-color: black; height: 30px;">
          This is a div element with an inline style
        </div>
      </body>
    </html>

     

    In the HTML code I have stated that the font-family of the document is Arial, the font-size is 1.1em, and the style for the <div> element is a white text and a black background with an area of 30px height. When you have an element that needs a specific style that will not be applied to any other element, you may consider using the element's style attribute to define this style.

    More Style Sheets Articles
    More By Michael Youssef


     

    STYLE SHEETS ARTICLES

    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables
    - CSS: Working with Text
    - CSS: Backgrounds
    - CSS for the Newbie
    - Styling Web Page Headers with Transparent Ba...
    - Creating Angled Corners with Transparent Bac...
    - Style Sheets for a Useful Links Page
    - Modifying the Look and Feel of Individual El...
    - Using Persistent Styles with Multiple Style ...
    - Working with Multiple Style Sheets
    - Using Web Page Grids in Yahoo Grid CSS


     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway