![]() |
CSS pseudo-elements are used to add special effects/styles to a specific part of the selected elements. A CSS selector selects the HTML element(s) for styling purposes. CSS selectors select HTML elements according to its id, class, type, attribute etc. For example, the ::before and ::after pseudo-elements can be used to insert content before or after an element’s content. Pseudo-elements are always declared using a double colon (::) syntax. They are always followed by the name of the pseudo-element and must be used in conjunction with a selector. Reason to learn about CSS pseudo-elements:
CSS pseudo-elements every CSS developer should know: CSS ::selection Selector: The selection selector is used to set the CSS property to the part of the document that is selected by the user (such as clicking and dragging the mouse across text).
Example: CSS
Output: In this example, the background color of the selected text is set to white and the text color is set to green. You can use any CSS properties that are applicable to text, such as font size, font weight, etc., to style the selected text. ![]() CSS ::selection Selector Note: This selector is not supported in internet explorer but works on all other major browsers. CSS ::placeholder Selector: The placeholder selector in the CSS pseudo-element is used to design the placeholder text by changing the text color and it allows to modify the style of the text.
Example: CSS
Output: In this example, the color of the text that appears in the input field when it is empty is set to green. ![]() CSS ::placeholder Selector Note: This selector is relatively new and may not be supported in all browsers. CSS ::marker Selector: The ::marker selector in CSS is used to change the marker properties. Here marker is the marker box of a list item.
Example: CSS
Output: In this example, the “::marker” pseudo-element is used to change the color of the markers in an ordered list ![]() CSS ::marker Selector Note: It is not supported in all browsers, so it’s always better to check the compatibility of your styles before only. CSS ::first-letter Selector: The ::first-letter selector is used to applying the style to the first letter of the first line of a block-level element, the condition is it should not be preceded by other content ( such as images or inline tables).
Example: CSS
Output: In this example, the first letter is displayed in the color & font size that we have set. ![]() CSS ::first-letter Selector Note: It is very important to know that it will work with block-level elements & not with inline elements. CSS ::first-line Selector: The ::first-line selector in CSS is used to apply style to the first line of a block-level element.
Example: CSS
Output: In this example, the first line of the paragraph is displayed in green just like we have set. ![]() CSS ::first-line Selector Note: It is very important to know that it will work with block-level elements & not with inline elements. Conclusion: Thus, we learned about the CSS pseudo-elements every CSS developer should know about & it’s the importance which ultimately results in better user experience, increased flexibility, better maintenance & increased visual enhancements of the code. |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |