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
Home Improvement
Shop
Prepaid Phone Card
Server Racks
Promos and Premiums
Desktop Computers
Remote Online Backup
Rackmount LCD Monitor
Baby Photo Contest
Auto Insurance Quote
Imprinted Promotions
PDA Phones & Cases
Promotional Pens
Cell Phones

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


Web Devs:
Moonlight as a Game Developer and Win Cool Prizes by Accepting the RIA Run Challenge

Now, your mission--should you choose to accept: Take your shot at gaming stardom if you think you might have what it takes to build a cool RIA game and you could win an Xbox 360 or other fabulous prizes. Hurry! You only have until May 15, 2008 to enter. »

 
Article:
Leveraging Your Flash Development with Silverlight

You're not giving up Flash any time soon (and we don't blame you.) But if you could get your Flash application working in Silverlight, why wouldn't you? We show you the tools and techniques required to have your rockin' Flash application rolled for Silverlight. Learn more here. »

 
Article:
What Does it Take to Build the Best RIA?

With the proliferation of Rich Interactive Application (RIA) platform choices out there, you no longer have to take a one-size-fits-all approach to developing your next RIA application. Knowing the strengths (and weaknesses) of each platform can help you to decide the best RIA for your next application. »

 
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

Selectors

There are four different kinds of selectors that you can use to add style to your web pages.

  • Type Selectors
  • Descendant Selectors
  • Attribute Selectors
    • Class
    • ID
  • External Selectors
    • Pseudo-Classes
    • Pseudo-Elements

Type Selectors

Type Selectors are the simplist to use in that they are taken from the name of the HTML elements with which you are already familiar.

H1 { color: blue }

Descendant Selectors

Sometimes it happens that you've given two elements the same value and then find that you have to include one within the other. You can change this one instance by creating a Descendant Selector which is a combination of the two. In effect, what you are saying is "give all instances of EM that are included in H3 the background value of yellow".

H3 { color: blue }
EM { color: blue }
H3 EM { background: yellow}
Important Statement
<H3><EM>Important</EM> Statement</H3>

Attribute Selectors

There are two types of Attribute Selector, CLASS and ID. CLASS Selectors are preceded by a dot (.); ID Selectors are preceded by a hash mark (#). The flag characters, (the dot and hash mark) signal the type of selector to follow.

<STYLE TYPE="text/css">
  .forest { color: green }
  .danger { color: red }
  #control { color: blue }
</STYLE>

green things

fire hazards

more green things
more fire hazards
  • things that burn
  • things that don't burn

water


<P class="forest">green things
<P class="danger">fire hazards
</P>
<EM class="forest">more green things</EM>
<BR>
<EM class="danger">more fire hazards</EM>
  
<UL>
<LI class="danger">things that burn
<LI class="forest">things that don't burn
</UL>
  
<P id="control"> water </P>
  

Naming Classes
You might decide that your web pages should have some sort of emphasised introductory paragraph, say an abstract. You think at first that they should use italic font, so you call the new class 'italic'. Later you discover that italic font is hard to read on some platforms so you settle on giving abstracts a normal font on a background color of light yellow. Thanks to style sheets, you only have one place to change, and all occurrences of 'italic' class will now render as you intend - but the all web pages still say 'class=italic' - very confusing! Much better is to name the class 'abstract', reflecting the purpose rather than the implementation.

<STYLE TYPE="text/css">
.forest { color: green }
.danger { color: red }
</STYLE>

test forest

test danger

no style

test forest
italic

<P class="forest">test forest
<P class="danger">test danger
<P> no style
<P class="forest">test forest
<BR>
<EM class="danger">italic</EM>
	

CLASS Selector

The CLASS Selector begins with the flag character, followed by the 'class name' of your choice. It is better to choose class names according to their purpose rather than a name that describes their color or style. For example, if you were to 'mark' every instance of danger signals in an article about forest fires with a class selector of .red, but later decided to change the style to bolded text you would have to remember that danger signals were red. It would be better to name the selector danger to make it easier to remember at some date in the distant future.

ID Selector

The value of the ID attribute may not be repeated anywhere within the document. If you have an ID value of "#control { color: blue }" you may not use it to define two different elements.

  <P id="control"> water </P>
  <EM id="control"> chemicals </EM>
  

The above would not be allowed. A different ID would need to be assigned for each element.

  #control { color: blue }
  #control2 { color: blue }

water

chemicals
  <P id="control"> water</P>
  <EM id="control2">chemicals</EM>

External Selectors:
Pseudo-Classes and Pseudo-Elements

Pseudo-classes and Pseudo-elements allow for formatting effects that don't correspond to regular HTML tags or attributes, e.g. the first line or letter of a paragraph, or visited links.

Pseudo-classes

The A (anchor) element is the only one that currently uses pseudo-classes. You're probably familiar with this concept from specifying link colors within the BODY element.

<BODY	link 	= "blue"
		vlink	= "purple"
		alink	= "red"
	>
<STYLE TYPE="text/css">
	A:link { color: blue }
	A:visited { color: purple }
	A:hover { color: green }
	A:active { color: red }
</STYLE>

Pseudo-elements

Currently there are only two pseudo-elements, neither of which are widely supported.

  P:first-line { font-style: italic }
  P:first-letter { font-size: 24pt }
first-line properties:
first-letter properties:

Additional Resources:

CSS Rules
Putting Style Sheets in Perspective: Table of Contents
Methods of Combining The Style Sheet With HTML


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