(Cascading Style Sheets)
Used to describe the presentation of HTML document
To add styles to the document could be used of the following methods:
Copyright By PowCoder代写 加微信 powcoder
Import external file with styles
Add inline styles to specific element
Add styles directly to the document
Which one to use depends on the situation. Usually most of the styles stores in the external file, but some the most critical styles could be added to the document or as inline styles
SSC tropmI
CSS file built from the list of CSS Rules
CSS Rule has 3 parts:
Selector – define the elements to which the rule applies
Property – one of the style property
Value – one of the possible value for the given property
erutcurtS SSC
* – Selects all the elements on the page Better to avoid using universal selector unless it’s necessary
rotceles lasrevinU
tagName – Selects all the elements with the given node type
rotceles epyT
.className – Selects all the elements with the given class
Page could contains any number of elements with the same class name
rotceles ssalC
#id – Selects the element with the given id Page should contains only one element for each ID
rotceles DI
selector[attr=value] – Selects all the elements with the given attribute pair – name/value
rotceles etubirttA
Combinators establish a relationship between selectors
srotanibmoC
selector:pseudo-class – Selectes the elements with a special state
sessalc-oduesP
selector::pseudo-element – Used to create cosmetic content for the element or allows to style a specific part of the element
stnemele-oduesP
In CSS rules applied to the element in the order which they are written in the document
That means the value of the property from the last rule will override values of the same property for all other rules which are target this element
Many properties are inheriting their values from the parents of the element So you don’t need to write a rule for every element
And in opposite need to be careful and reset the styles from the parents if they are not expected for this particular element
ecnatirehnI
If an element has multiple rules with the same property, to decide what value should be used, beside cascade browser will look on the specificity of each selector and choose the highest one
Specificity calculated by the number of each selector type: X-0-0-0 : inline styles have more specificity than any selectors
0-N-0-0 : number of id selectors 0-0-N-0 : number of class selectors
0-0-0-N : number of type selectors https://specifishity.com
yticificepS
Overrides any other declarations of the property applied to the element (even inline styles)
Better to avoid using !important rule as it hard to debug and maintain the code when it contains it
tnatropmi!
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com