Selectors
These are used to select the HTML elements for styling.
Element Selector :
- This selector selects the HTML element by element name.
Example :
HTML
CSS
This will produce the following result −
id Selector :
- This selector is used to select a particular HTML element by using id attribute.
- This id should be unique for every element which you want to style.
- To select an element with id name, write a # followed by id name(e.g. #idName).
Example :
HTML
CSS
This will produce the following result −
Class Selector :
- This selector is used to select a HTML element by using class attribute.
- Same class name can be used to style multiple elements.
- To select an element with class name, write a . followed by class name(e.g. #className).
- HTML elements can have more than one class.
Example :
HTML
CSS
This will produce the following result −
Universal Selector :
- The universal selector (*) selects all HTML elements on the page.
- Generally used to remove default styles of a browser.
Example :
CSS
Pseudo classes
A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a box color when the user’s pointer hovers over it.
example : :hover :focus :first-child
selector specificity
Specificity is the means by which browsers decide which CSS property values are the most relevant to an element and, therefore, will be applied. Specificity is based on the matching rules which are composed of different sorts of CSS selectors.
Pseudo-element Selector
Pseudo-elements in CSS allows you to insert content onto a page without it needing to be in the HTML.While the end result is not actually in the DOM, it appears on the page as if it is.
example : ::before ::after ::first-letter