Home arrow Style Sheets arrow CSS: Pseudo
STYLE SHEETS

CSS: Pseudo


We left off learning about the various positions in CSS. In this tutorial we will cover the pseudo classes and pseudo elements, which allow us to add special effects to our selectors. An example would be roll-over effects on hyperlinks, or making the first letter of a sentence larger and a different color than the rest of the text.

Author Info:
By: James Payne
Rating: 5 stars5 stars5 stars5 stars5 stars / 15
May 19, 2008
TABLE OF CONTENTS:
  1. · CSS: Pseudo
  2. · Dealing with the :first Line Pseudo Element
  3. · Pseudo Classes
  4. · A Preview of Mouse-over Effects

print this article
SEARCH DEVARTICLES

CSS: Pseudo
(Page 1 of 4 )

We will begin our discussion by working with Pseudo-elements.

Dealing with the :first Letter Pseudo Element

The :first letter Pseudo Element allows us to change the first letter of our selector by adding a special effect to it. Below is an example of how to make the first letter larger than the rest of the text:


<html>

<head>

<style type="text/css">

p:first-letter

{

font-size:xx-large

}

</style>

</head>

<body>

<p>

Once upon a time in a land, right down the street, there lived this fat ugly dude that owed me a lot of money. So I sent the politically stupid yet Kung-Fu intelligent Chuck Norris to his house to collect.

</p>

</body>

</html>

Go ahead and try it out. Isn't that a beautiful fairy tale? As you can see, the "O" in "Once" becomes huge. Now let's add some other effects to it. Since this wondrous fairy tale is all about whippin' that butt, let's make the "O" red, like blood:


<html>

<head>

<style type="text/css">

p:first-letter

{

color: red;

font-size:xx-large

}

</style>

</head>

<body>

<p>

Once upon a time in a land, right down the street, there lived this fat ugly dude that owed me a lot of money. So I sent the politically stupid yet Kung-Fu intelligent Chuck Norris to his house to collect.

</p>

</body>

</html>

And finally, we will add some more effects to our first letter to make it look even more spiffy:


<html>

<head>

<style type="text/css">

p:first-letter

{

color: red;

font-size:xx-large;

text-decoration: overline underline;

}

</style>

</head>

<body>

<p>

Once upon a time in a land, right down the street, there lived this fat ugly dude that owed me a lot of money. So I sent the politically stupid yet Kung-Fu intelligent Chuck Norris to his house to collect.

</p>

</body>

</html>

You can add all of the following to :first letter: 

  • font properties

  • color properties

  • background properties

  • margin properties

  • padding properties

  • border properties

  • text-decoration

  • vertical-align (only if 'float' is 'none')

  • text-transform

  • line-height

  • float

  • clear

You can also mix your classes with your pseudo elements, allowing you to add effects to all of your elements of the same class easily. Behold!

<html>

<head>

<style type="text/css">

div.cool:first-letter

{

color: red;

font-size:xx-large;

text-decoration: overline underline;

}

</style>

</head>

<body>

<div class="cool">

Once upon a time in a land, right down the street, there lived this fat ugly dude that owed me a lot of money. So I sent the politically stupid yet Kung-Fu intelligent Chuck Norris to his house to collect.

</div>

<br>

<div class="cool">Needless to say, there was much bloodshed.</div>

</body>

</html>


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Padding Overview
- CSS: Margins Overview
- Top CSS3 Button Tutorials
- More Top CSS3 Tutorials for Animation and Im...
- CSS Mega Menus: Adding Extra Sections
- CSS Mega Menus
- CSS3 Accordian Menu: Horizontally Display Hy...
- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials