- inline
- internal element
- external stylesheet
Selectors target which elements on our page will be styled
- Target all elements of a specific tag:
- target elements based on its attributes
- classes
- ids
- pseudo classes
- attributes
- combinators
- elements depending are they are placed relative to others in the document
Child element inherits some CSS properties from the parents in the document tree.
A particular element in the HMTL might be the target of several style declarations resulting in conflicting rules that the browser needs to resolve.
The styles in cascaded style sheets are processed by the web browser in a certain order that we call the cascade:
I. Sort by weight and origin of the styles II. Sort by specificity - more specific selectors will override more general ones III. Sport by order specified
- !important user styles
- !important author styles
- Author styles
i. inline style sheets ii. internal style sheets iii. external style sheets
- User styles
- browser default styles
Each selector of a style declaration has a calculated specificty.
a= presence of an inline style b= calculate the number of ID attributes in the selector c= calculate the number of classes, pseudo-classes and other attributes in the selector d= calculate the number of element names in the selector
a1000, b100, c10, d1
*
has a 0 specificity
Will give the priority to this rule. Not to be abused
ex.:
p { color: red !important; }
#quote { color: blue; }
This will be red
References: css specificity CSS Selectors !important rule