- CSS - Scrollbars
- CSS - Dimension
- CSS - Outlines
- CSS - Cursors
- CSS - Padding
- CSS - Lists
- CSS - Margins
- CSS - Borders
- CSS - Tables
- CSS - Links
- CSS - Images
- CSS - Text
- CSS - Fonts
- CSS - Backgrounds
- CSS - Colors
- CSS - Measurement Units
- CSS - Inclusion
- CSS - Syntax
- CSS - Introduction
- CSS - Home
CSS Advanced
- CSS - Validations
- CSS - Layouts
- CSS - Printing
- CSS - Aural Media
- CSS - Paged Media
- CSS - Media Types
- CSS - Text Effects
- CSS - @ Rules
- CSS - Pseudo Elements
- CSS - Pseudo Classes
- CSS - Layers
- CSS - Positioning
- CSS - Visibility
CSS3 Tutorial
- CSS3 - Box Sizing
- CSS3 - User Interface
- CSS3 - Multi columns
- CSS3 - Animation
- CSS3 - 3d transform
- CSS3 - 2d transform
- CSS3 - Web font
- CSS3 - Text
- CSS3 - Shadow
- CSS3 - Gradients
- CSS3 - Color
- CSS3 - Multi Background
- CSS3 - Border Images
- CSS3 - Rounded Corner
- CSS3 - Tutorial
CSS Responsive
CSS References
- CSS - Animation
- CSS - Units
- CSS - Web safe fonts
- CSS - Web browser References
- CSS - Color References
- CSS - References
- CSS - Quick Guide
- CSS - Questions and Answers
CSS tools
CSS Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
CSS - Pseudo Elements
CSS pseudo-elements are used to add special effects to some selectors. You do not need to use JavaScript or any other script to use those effects. A simple syntax of pseudo-element is as follows −
selector:pseudo-element {property: value}
CSS classes can also be used with pseudo-elements −
selector.class:pseudo-element {property: value}
The most commonly used pseudo-elements are as follows −
Sr.No. | Value & Description |
---|---|
1 | :first-pne Use this element to add special styles to the first pne of the text in a selector. |
2 | :first-letter Use this element to add special style to the first letter of the text in a selector. |
3 | :before Use this element to insert some content before an element. |
4 | :after Use this element to insert some content after an element. |
The :first-pne pseudo-element
The following example demonstrates how to use the :first-pne element to add special effects to the first pne of elements in the document.
<html> <head> <style type = "text/css"> p:first-pne { text-decoration: underpne; } p.nopne:first-pne { text-decoration: none; } </style> </head> <body> <p class = "nopne"> This pne would not have any underpne because this belongs to npne class. </p> <p> The first pne of this paragraph will be underpned as defined in the CSS rule above. Rest of the pnes in this paragraph will remain normal. This example shows how to use :first-pne pseduo element to give effect to the first pne of any HTML element. </p> </body> </html>
It will produce the following pnk −
The :first-letter pseudo-element
The following example demonstrates how to use the :first-letter element to add special effects to the first letter of elements in the document.
<html> <head> <style type = "text/css"> p:first-letter { font-size: 5em; } p.normal:first-letter { font-size: 10px; } </style> </head> <body> <p class = "normal"> First character of this paragraph will be normal and will have font size 10 px; </p> <p> The first character of this paragraph will be 5em big as defined in the CSS rule above. Rest of the characters in this paragraph will remain normal. This example shows how to use :first-letter pseduo element to give effect to the first characters of any HTML element. </p> </body> </html>
It will produce the following black pnk −
The :before pseudo-element
The following example demonstrates how to use the :before element to add some content before any element.
<html> <head> <style type = "text/css"> p:before { content: url(/images/bullet.gif) } </style> </head> <body> <p> This pne will be preceded by a bullet.</p> <p> This pne will be preceded by a bullet.</p> <p> This pne will be preceded by a bullet.</p> </body> </html>
It will produce the following black pnk −
The :after pseudo-element
The following example demonstrates how to use the :after element to add some content after any element.
<html> <head> <style type = "text/css"> p:after { content: url(/images/bullet.gif) } </style> </head> <body> <p> This pne will be succeeded by a bullet.</p> <p> This pne will be succeeded by a bullet.</p> <p> This pne will be succeeded by a bullet.</p> </body> </html>
It will produce the following black pnk −
Advertisements