Cascading Style Sheet Lecture 5
Cascading Style Sheet Lecture 5
PSEUDO-CLASSES
PSEUDO-CLASSES
Syntax
The syntax of pseudo-classes:
selector:pseudo-class {
property: value;
}
PSEUDO-CLASSES
Anchor Pseudo-classes
Links can be displayed in different ways:
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited link */
a:visited {
color: #00FF00;
}
/* mouse over link */
a:hover {
color: #FF00FF;
}
PSEUDO-CLASSES
/* selected link */
a:active {
color: #0000FF;
}
Note: a:hover MUST come after a:link and a:visited in the CSS definition
in order to be effective! a:active MUST come after a:hover in the CSS
definition in order to be effective! Pseudo-class names are not case-
sensitive.
PSEUDO-CLASSES
p:first-child {
color: blue;
}
PSEUDO-CLASSES
p:last-child {
background: #ff0000;
}
PSEUDO-CLASSES
p:last-child {
background: #ff0000;
}
PSEUDO-CLASSES
input:focus {
width: 250px;
}
PSEUDO-ELEMENTS
PSEUDO-ELEMENTS
}
Note: The ::first-line pseudo-element can only be applied to block-level
elements.
PSEUDO-ELEMENTS
::selection {
color: red;
background: yellow;
}