CSS
CSS Introduction
CSS Selectors
CSS Color
CSS Background
CSS Border
CSS Margin
CSS Padding
CSS Box Model
CSS Text
CSS Font
CSS Link
CSS List
CSS Overflow
CSS Display
CSS Combinators
CSS Pseudo-classes
CSS Navigation Bar
CSS Hover
CSS Z-index
CSS Media Queries
CSS Shadow
CSS 2D Transform
CSS Animations
CSS Button
CSS FlexBox
CSS Grid
CSS Pagination
CSS Selectors
CSS selectors allow us to choose specific elements and apply styles to them.
Suppose we want to add a custom style to only a specific tag(s). There, we can make use of CSS selectors.
There are different types of CSS selectors, which are as follows:
Universal Selector
Universal selector represented by * targets all the HTML elements on the page.
Element Selector
The element selector selects the target element based on the specific type.
Suppose you want to underline all the <p> tags; in this case, the element selector will be the best choice.
The syntax of Element Selector is as follows:
ID Selector
The ID selector targets the elements based on the specific ID.
It is written with the hash # character followed by the ID name in the style sheet.
The syntax of ID Selector is as follows:
Class Selector
The class selector does the same job as the id selector, a class selector helps group various types of elements.
Suppose, we want to give a custom style to a specific group of elements. In this case, the class selector is the best option.
It is written with the period . character followed by the class name in the style sheet.
Group Selector
The group selector is used to minimize the code. Commas , are used to separate each selector in a grouping.
This reduces the number of lines of code. The code also looks clean.
The syntax of Group Selector is as follows: