Two columns Three columns Mixed cols and rows Gallery Archives Clean & Clear Dark or Black High Contrast/ Impact Blog Designs New Corporate/ Professional Unconventional Designs Liquid layouts Web Design Firms Our Favorites What's Popular Last 20 submissions
Horizontal Menus Vertical Menus Multiple/ Nested Levels

CSS Examples Pseudo-classes of CSS

Date: 01/16/2005 Pseudo-classes of CSS

Author: CSS Drive

Pseudo-class are an interesting group of selectors in CSS that apply to elements when they're in a certain state or condition, such as with a link, when the mouse is over it. This makes for some interesting and lightweight visual effects.

Pseudo-class (CSS2.1) Description Applies to
:link Applies to links that have not been visited. links
:visited Applies to links that have been visited. links
:hover Applies to an element which the mouse is currently over. all
:active Applies to an element currently being activated by the user (ie: the mouse is held down over). all
:focus Applies to an element while it has the user focus. all
:first-child Matches an element that is the first child of some other element. all
:first-letter Applies to the first letter of a paragraph. block level elements
:first-line Applies to the first formatted line of a paragraph. block level elements
:lang Applies to an element when it's in the designated language. all

The first four pseudo classes are typically used on links, even though 3rd and 4th apply to elements in general. This is because in IE (as of IE6), ":hover" and ":active" don't work on elements other than links.

CSS Example #1 (link pseudo-classes):

A:link    { color: red }    /* unvisited links */
A:visited { color: blue }   /* visited links   */
A:hover   { background-color: yellow } /* user hovers over link*/
A:active  { color: lime }   /* active links    */

This is a very common CSS definition to manipulate the look of links on the page. The order in which you define the four selectors is important, typically known as LVHA (link visited hover active). If you alter the order, some of your selectors will be suppressed and not take effect due to the way CSS handles cascade/ ordering.

CSS Example #2 (:first-child pseudo-class):

img:first-child{ border: 1px solid gray; }

This applies a border to any image that is the first child of another element.

CSS Example #3 (:lang pseudo-class):

:lang(fr) { font-weight: bold; }

This gives elements that are determined by the browser as French (using a variety of methods) a bold font.

Comments (37)

This is a nice tutorial. Thanks for the effort.

regards,
http://www.bahamut.net

#1: forcez5 on 11/27 at 04:06 AM

i agree others. this is good work.

#2: steven on 11/27 at 08:02 AM

This site there is full of information in learning CSS, highly recommended by me!

Regards,
James

#3: James on 12/05 at 12:33 AM

yes this is really good work.
http://erikalinks.com
http://rosezar.com

#4: erikalinks on 12/05 at 02:25 AM

Thank You for another very interesting article. It's really good written and I fully agree with You on main issue, btw. I must say that I really enjoyed reading all of Your posts. It’s interesting to read ideas, and observations from someone else’s point of view… it makes you think more. So please try to keep up the great work all the time. Greetings

#5: Aukcje on 12/05 at 12:59 PM

great article, thanks, keep up good work

#6: dieta on 12/16 at 02:28 AM

Hey , thank you very much for this great stuff! Keep up your great work! Greetings Daniel

#7: Muskelaufbau on 12/16 at 08:43 AM

Yes this is really good work.
http://www.myplanet.pl

#8: Linki on 01/03 at 01:32 PM

looks very interesting.
thanks for article.

regards, http://stereo-vinyl.com/

#9: Stereo Vinyl on 01/04 at 05:35 PM

Keep your good work,
this is one the best css introduction i have seen before.
<a href=http://www.qualifiedweblinks.com>link drectory</a>

#10: web links on 01/17 at 05:51 AM

Post a Comment: Guest (Login or Register)

Name: (Required)

Email: (Required)

(NOT shown on page)

URL:

(Shown on page if entered)

Comments: (Required)

Remember my personal information
Notify me of follow-up comments?

Submit the word you see below:


CSS Forums

CSS Forums: latest threads Last Post Info
Cant design (1) 05/16/2008 12:28 pm
By: tarik
How to show an entire pdf in one div (2) 05/14/2008 11:07 am
By: Grundic
Starting A Web Design Business - How Do I Attract Customers? (10) 05/13/2008 02:37 pm
By: april
Download.. Pacific Wings multicolor menu (1) 05/13/2008 03:05 am
By: sebreh
Check out this website I am working on CRITIQUE. (5) 05/13/2008 01:20 am
By: abran