Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
 Discussion Forums
 HTML, XML, JavaScript...
 Software Reviews
 Editors,Others...
 Top100
 JavaScript Tutorials, ...
 Tutorials
 ASP, CSS, Databases...
 Discussion List
 FAQ, Roundup, Configure ...
 Authoring
 HTML, JavaScript, CSS...
 Design
 Layout, Navigation,...
 Graphics
 Tools, Colors, Images...
 Software
 Browsers, Editors, XML...
 Internet
 Domains, E-Commerce, ...
 WDVL Resources
  Intermdiate, Tutorials,...
 WDVL
 Discussion Lists, Top 100,...
 Technology Jobs


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us
Website Load Testing
Online Education
Online Universities
GPS
Corporate Gifts
KVM over IP
Laptops
Web Hosting Directory
Disney World Tickets
Cell Phones
Desktop Computers
Auto Insurance Quote
Promotional Products
Promotional Pens

Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Just because Web sites are easy to build these days, that doesn't mean it's easy to build a quality Web site that meets your business objectives.

Before developing your next Web site, or redesigning an existing site, download this Internet.com eBook to guide you through the process and plan your project, whether you're developing a site in-house or outsourcing the project.
Register now for your free Internet.com membership to download your complimentary eBook. Membership will also give you access to:

eBook library         Whitepapers         Webcasts
Newsletters         WinDrivers
Top 10 Articles
  1. Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions
  2. JavaScript Tutorial for Programmers
  3. Design
  4. JavaScript Tutorial for Programmers - Objects
  5. JavaScript Tutorial for Programmers - JavaScript Grammar
  6. JavaScript Tutorial for Programmers - Versions of JavaScript
  7. Cascading Style Sheets
  8. JavaScript Tutorial for Programmers - Embedding JavaScript
  9. JavaScript Tutorial for Programmers - Functions
  10. Authoring JavaScript
Domain Name Lookup
Search to find the availability of a domain name. Just enter the complete domain name with extension (.com, .net, .edu)

June 17, 1998

Putting Style Sheets in Perspective

Inheritance

To avoid a multitude of frustration, you'll need to understand the tree structure and inheritance, and how they relate to Style Sheets. Should be easy... right? We all know HTML and how the elements relate to each other...... but do we ? Once you're faced with Style Sheets, things can look a whole lot different, especially when your style is lost after you insert a table or a list.

Your document will take on the stylistic values set in the BODY declaration unless other selectors and rules are added to the style sheet. General rules, such as that specified by the BODY declaration will be over ridden by more specific rules such as P.

A child element is one contained within another, which is the parent, so in

<p> ... <b> ... </b> ... </p>

P is the parent and B is the child.

The following examples on this page will be based on this style sheet:-

<STYLE TYPE="text/css">
BODY	{color:		#9966FF;
	background:	#FFFFCC;
	font-family:	Arial;
	}
P	{color:		navy}
UL	{color:		maroon }
TD 	{color: 	green}
</STYLE>

The UL Selector in the style sheet specifies that unordered lists should be maroon, therefore all LI elements will take on the color specified unless it is overridden by inheritence.

<UL>
<LI>	item one
<LI>	item two
<LI>	item three
</UL>
  • item one
  • item two
  • item three

In the example above, the UL Selector in the style sheet specified that the list items should be maroon. They inherited the Arial font from the BODY Declaration, the maroon color from the UL Declaration. Had a font-family been specified in the UL declaration, it would have over ridden the BODY selector declaration.

There is no OL selector in the style sheet, therefore the OL list inherits it's attributes from the BODY selector. (Remember, lists and paragraphs are both children of BODY; the list will not inherit the attributes of the P selector).

<OL>
<LI>	item one
<LI>	item two
<LI>	item three
</OL>
  1. item one
  2. item two
  3. item three

Placing the same two lists into a table produces one maroon list, and one green one. How come the OL list turned green? Inheritance is the answer. Once the OL list was moved to the inside of a table it took on the color value set in the TD Declaration. So, how come the maroon list didn't turn green? The UL selector in the style sheet is more specific than the TD selector since the list is contained inside of the table.


<TABLE BORDER=1>
<TR><TD>

<UL>
<LI>	item one
<LI>	item two
<LI>	item three

</UL>

<OL>
<LI>	item one
<LI>	item two
<LI>	item three
</OL>

</TD></TR>
</TABLE>

  • item one
  • item two
  • item three
  1. item one
  2. item two
  3. item three

The cells in the table below are displaying the green text specified in the TD declaration. Notice though, that placing a P element inside of a table cell over rides the TD color value, replacing it with the P selectors color value.

<CENTER>
<TABLE border=1><TR>
	<TD>Table Cell 1</TD>
	<TD>Table Cell 2</TD>
	<TD><P>Table Cell 3</TD>
</TR></TABLE>
</CENTER>
Table Cell 1 Table Cell 2

Table Cell 3

Elements that are not included in the style sheet as selectors will inherit the properties of their parent element. In the example below, the B and I elements are inheriting the properties of the P selector.

<P>
  <B>bold paragraph</B><BR>
  <I>italic text</I><BR>
</P>

bold paragraph
italic text


To turn off the navy blue text within the table above, I closed the P element.

Additional Resources:

Methods of Combining The Style Sheet With HTML
Putting Style Sheets in Perspective: Table of Contents
Summary Part One


Up to => Home / Authoring / Style / Sheets / Intro




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers