written 6.8 years ago by | • modified 2.8 years ago |
Subject: Advanced Internet Technology
Topic: Responsive web design with HTML5 and CSS3
Difficulty: Medium
written 6.8 years ago by | • modified 2.8 years ago |
Subject: Advanced Internet Technology
Topic: Responsive web design with HTML5 and CSS3
Difficulty: Medium
written 6.7 years ago by | • modified 6.7 years ago |
CSS Pseudo-classes
Syntax
selector:pseudo-class {property: value}
CSS classes can also be used with pseudo-classes −
selector.class:pseudo-class {property: value}
The most commonly used pseudo-classes are as follows −
1. :link - Use this class to add special style to an unvisited link.
<html>
<head>
<style type="text/css">
a:link {color:#000000}
</style>
</head>
<body>
<a href="">Black Link</a>
</body>
</html>
2. :visited - Use this class to add special style to a visited link.
<style type="text/css">
a:visited {color: #006600}
</style>
3. :hover - Use this class to add special style to an element when you mouse over it.
<style type="text/css">
a:hover {color: #FFCC00}
</style>
4. :active - Use this class to add special style to an active element.
5. :focus - Use this class to add special style to an element while the element has focus.
6. :first-child - Use this class to add special style to an element that is the first child of some other element.
7. :lang - Use this class to specify a language to use in a specified element.
<html>
<head>
<style type="text/css">
/* Two levels of quotes for two languages*/
:lang(en) { quotes: '"' '"' "'" "'"; }
:lang(fr) { quotes: "<<" ">>" "<" ">"; }
</style>
</head>
<body>
<p>...<q lang="fr">A quote in a paragraph</q>...</p>
</body>
</html>
Pseudo-Elements
Syntax
The syntax of pseudo-elements:
selector::pseudo-element {
property:value;
}
::after - Insert something after the content of each mentioned element
::before - Insert something before the content of each mentioned element
::first-letter - Selects the first letter of each mentioned element
::first-line - Selects the first line of each mentioned element
::selection - Selects the portion of an element that is selected by a user