I've been reading up on specificity and, quite frankly, I'm surprised that I didn't know about this properly before, since I've witnessed the very issues that specificity can give if CSS is declared in the wrong manner.
So, I've been doing a little research on the subject, and I now understand the rule for calculating specificity. However, during my findings, I've been left with three questions which I was hoping you guys could help me out with.
Firstly, when relating to CSS specificity, I've noticed that one source includes pseudo elements in the calculation, while another tells you to leave them out of the calculation. Is this purely an optional thing, or should I include them?
Secondly, is there any specific reason why I should declare classes above identifiers? For instance, I've already sectioned my development CSS file, and in the 'footer' section, I have
#footer
,#footer-container
,.grid
and.one-third
, declared in this order. Is this perfectly fine, or should I switch them around? The defined rules are below, to show that both classes don't contain any conflicting properties:#footer { background: #e4e4e4; border-top: 1px solid #eeeeee; border-bottom: 1px solid #666666; overflow: hidden; padding-bottom: 1em; width: 100%; } #footer-container { margin: 0 auto; width: 100%; min-width: 1000px; } .grid { margin-right: 2.1%; float: left; display: inline; position: relative; } .one-third { width: 31.9%; }
Lastly, just a quick question about listing CSS properties in alphabetical order. I fully understand that this is optional, but using my declaration for
#footer
above as an example, is there any preference forborder
,margin
orpadding
, as in alphabetical (bottom; left; right; top
), or declared as written in shorthand (top; right; bottom; left
)?
Thank you very much!