Does the css class always use the best idea to get rid of styling issues?
3 answers
id
is an identifier and ideally should only be used for one element, whereas it class
can be used multiple times for multiple elements.
CM: Id vs Class
+2
phpBOY
a source
to share
The class will not always override the ID - given two conflicting rules for the same element, the browser will calculate the score for each rule based on the specifics of the rule. Each part of the rule scores points, then the rule with the most applicable points.
- html selectors (div, p, etc.) - +1 Class selectors
- (.class) - +10
- id selectors (#id) +100
So for your example:
#content ul li a {font-size:10px} = 100 + 1 + 1 + 1 = 103
#content .demo ul li a {font-size:15px} = 100 + 10 + 1 + 1 + 1 = 113
Hope it helps
+1
a source to share