What is Selectors ?
Selectors: CSS selectors are used to select those content which you want to style. In which HTML elements is selected by CSS selectors according to its id, class, type attribute etc.
Types of selectors in CSS:
- CSS Element selectors.
- CSS Id selectors.
- CSS Class selectors.
- CSS Group selectors.
- CSS Universal selectors.
1. CSS Element selectors: This select the element by name. Element Name means Tag Name. Example: if there is a more than one paragraph tag are available in html code, and if we apply css property to paragraph tag ,then this property will apply on all paragraph which are available in the code.
Example:
2.CSS Id Selectors: When we want to provide a unique property to any particular tag then Id will be used. Id selector represent by (#) symbol. Suppose in your html code there is a more than one paragraph tag are available and you want to apply property only in a one paragraph rather than all paragraph then you need to use Id selector. In any tag use id Selector and allocate a name of the Id. CSS Property will be assigned by using Internal CSS, or external CSS.
Example:
3.CSS class Selectors: This Selector select HTML Tag with class attribute. Class Selector denoted with (.) dot symbol and follow by class name .
1.Class name always start with alphabet.
2.No special character use in classname expect hyphen & underscore.
Example:
4.CSS Group selectors: The grouping selector is used to select all the element with the same css style. With the help of grouping, code will be minimized. Complexity of the code will be reduced. In which comma are used to separate selector in group.
Example:
Here you can see we have applied css properties to all elements and we separate them by comma.
5. CSS Universal selectors: This selector select all the element in the HTML Code. Whenever we want to apply any property to all elements then assign those property in Universal selector. This Selector represented by the (*) asterisk symbol.
Example: