Selector {property : value ; }
CSS syntax can be divided into two parts
1 Selector
2 Declaration
a) Property
b) Value
To apply css to html element, we use selector to handle the css coding with the help of the selector, it determines which html element css will apply to. Some important selector of css is as follows -
1. Element selector
2. Id selector
3. Class selector
4. Group selector
5. Universal selector
Etc..
The html element to which css is to be applied is used as selector for the tag name of that element with the help of this selector that css can be applied to all tags of html except for some empty tag. Like <br> tag
Syntax :- tagName {property: value;}
Example :- p {color: red;}
Any name is given in the value using the id attribute in the tag name of the html element to which css is applied, use this name as a selector, with the help of this selector, you can apply css to any element.
The html element to which css is applied is written after the hash symbol (#) of the id name of that element.
Syntax :- #idName {property : value ; }
Example :- #paragraph1 {color: red; }
Any name is given in value by using class attribute in the tag name of the element in which html element is to be applied, use this name as a selector. If you want to apply css, you can use the class name of that element in external and internal css.
Syntax
.className {property : value ; }
Example :- .paragraph2 {color: green; }
The html element to which css is to be applied is used as selector for the tag name of that element, it is called element selector but when using tag name of two or more element as selector, it is called group selector. It is written separately from comma (,), it is used to apply the same css style to many elements, this saves time, there is no need to write different css code for all elements, because this one The css code can be applied in more than one tag, so it is called group selector.
Example
h1 color: red; }
h3 { color: red; }
p { color: red; }
h1, h2, p { text-align: center; }
If you want to apply css to all elements of an html document file, then use it, for this, use the asterisk (*) symbol, so the same css style applies to all elements of different css for all elements. There is no need to write code, hence time is saved, it is called universal selector.
Syntax :- *{property : value ; }
Example :- * { color: red; }