spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

Pseudo-elements

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Just like pseudo-classes are used to select elements that have special properties that cannot be expressed with other kinds of selectors, the concept of pseudo-elements was created to apply style rules to portions of a document that cannot be otherwise selected.

Pseudo-elements are specified in selectors exactly as pseudoclasses are: by using a colon (:). The two types of pseudo-elements defined by CSS1 are first-letter and first-line. The first-letter pseudo-element selects a theoretical element that contains only the first letter of an element. The first-line pseudo-element selects a theoretical element that contains only the first line of an element.

Unfortunately, neither of these pseudo-elements are supported by current browsers. If they where, they could be used to create interesting effects such as drop capitals. The following example gives two rulesets and a P element to which they apply. The rendering of this element is actually a picture of what it should look like if a browser supporting typographical pseudo-elements displayed this paragraph. The first line of the element is made bold, and the first letter is made three times larger and floats to the left (I will explain these properties, like all the others I have used so far, in future tutorials).

P:first-line {
  font-weight: bold;
}
P:first-letter {
  font-size: 300%;
  float: left;
}
<P>This is a rather long paragraph that should 
wrap into more than one line if the viewing window 
is sufficiently narrow and the text is sufficiently 
long, which should be the case with most setups.
image of a pararaph of text with a drop-cap effect and a bold first line

That's all for this time, folks. This tutorial has covered the selector syntax described in CSS level 1. CSS2 defines some more advanced forms of selectors, but since these are currently unsupported by browsers, and are pretty specialised anyway, so we'll look at those later on. In tutorial 7, we'll take a peek at how a browser should combine style rules from embedded style sheets, linked style sheets, and STYLE attributes to decide which should apply to an element, and understand why Cascading Style Sheets, well, cascade...

Front Page1234567

http://www.internet.com

Produced by Stephanos Piperoglou

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/html/tutorial6/7.html
Created: September 24, 1998
Revised: September 24, 1998