Prev Page Next Page
Top

CSS Pseudo-elements

➢A CSS pseudo-element is used to style specified parts of an element.
Example
➢Style the first letter, or line, of an element
➢Insert content before, or after, the content of an element

The ::first-line Pseudo-element

➢The ::first-line pseudo-element is used to add a special style to the first line of a text.

EXAMPLE:

p::first-line {
     color: #ff0000;
     font-variant: small-caps;

}

Run


The ::first-letter Pseudo-element

➢The ::first-letter pseudo-element is used to add a special style to the first letter of a text.

EXAMPLE:

p.intro::first-letter {
     color: #ff0000;
     font-size: 200%;

}

Run


Multiple Pseudo-elements

➢Several pseudo-elements can also be combined.

EXAMPLE:

p::first-letter {
     color: #ff0000;
     font-size: xx-large;

}
p::first-line {
     color: #0000ff;
     font-variant: small-caps;

}

Run


CSS - The ::before Pseudo-element

➢The ::before pseudo-element can be used to insert some content before the content of an element.

EXAMPLE:

h1::before {
     content: url(smiley.gif);
}

Run


CSS - The ::after Pseudo-element

➢The ::after pseudo-element can be used to insert some content after the content of an element.

EXAMPLE:

h1::after {
     content: url(smiley.gif);
}

Run


CSS - The ::marker Pseudo-element

➢The ::marker pseudo-element selects the markers of list items.

EXAMPLE:

::marker {
     color: red;
     font-size: 23px;

}

Run


CSS - The ::selection Pseudo-element

➢The ::selection pseudo-element matches the portion of an element that is selected by a user.
➢The following CSS properties can be applied to ::selection: color, background, cursor, and outline.

EXAMPLE:

::selection {
     color: red;
     background: yellow;

}

Run


Prev Page Next Page