Photo by Martin Shreder on Unsplash
⭐ CSS Selectors with Examples⭐
Learn CSS selectors in a very easy way with examples and implement into your project. Happy Learning
CSS selectors are used for selecting the elements which you want to style. These selectors are broadly classified into multiple categories:
- Basic selectors
- Grouping selectors
- Combination selectors
- Pseudo selectors
Basic Selectors
Universal selectors The universal selector (*) selects all HTML elements on the page.
Type selectors This type of selector is used to match the elements by their node name.
Class selectors This type of selector is used to select the element with the given class name.
Id selectors This type of selector is used to select the element based on the value of its id attribute.
Attribute selectors The CSS attribute selector matches elements based on the presence or value of a given attribute.
Grouping Selectors
The grouping selector selects all the HTML elements with the same style definitions.
Combination Selectors
There are different types of combination selectors like +, >, " ",~, and many more.
Pseudo Selectors
Pseudo Selectors consist of pseudo-elements and pseudo-classes.
The simple difference between the two is that pseudo-elements (
::) are used to style a specific part of an element whereas pseudo-class (
:) is used to style a complete element.
Pseudo Elements
There are many pseudo elements but we are discussing most commonly used elements.
Syntax:
selection::psudo-element{
property:value;
}