Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-30-2012, 08:01 PM   PM User | #1
LRRoberts0122
New Coder

 
Join Date: Jul 2011
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
LRRoberts0122 is an unknown quantity at this point
CSS: Specificity

Can someone please explain the concept of specificity to me, or point me to an article that explains it thoroughly. I understand the basics of specificity:

A class beats an element selector.
An ID selector beats a class and element selector.
The style attribute beats the ID, class and element selectors.

I also know that a Universal Selector has a specificity of 0, 0, 0, 0, which I've read is not the same as having no specificity.

I've been using this website as reference to try and learn more about the specificity concepts of CSS:
http://css-tricks.com/specifics-on-css-specificity/

I'm particularly referring to the following example:
Code:
#footer *:not(nav) li
There are 0 style selectors, one ID selector, a universal selector, a psuedo-class selector, and two element selectors, however the outcome is:
0, 1, 0, 2

Is this because the universal selector has a specificity of 0, 0, 0, 0, and therefore, this is applied to whatever it is attached to?

So basically when people use universal selectors as a reset (bad, but using it as an example), it would be: 0, 0, 0, 0

If someone is using a universal selector on an element, (*ul li {font-style: italic;}) it would be: 0, 0, 0, 0

If someone is using a universal selector on a class, (*.error p {color: red;}) it would be: 0, 0, 0, 1

And so on an so forth, correct?

Thank you for any information that would help me further understand how this works!
LRRoberts0122 is offline   Reply With Quote
Old 10-01-2012, 01:53 AM   PM User | #2
Sammy12
Registered User

 
Join Date: Jun 2011
Posts: 1,063
Thanks: 12
Thanked 241 Times in 240 Posts
Sammy12 is on a distinguished road
These numbers aren't helping. I recommend not using them lol...

Here's how the lineup would look like from weak to strong.
Code:
#footer *:not(nav) li
#footer div:not(nav) li
#footer .class:not(nav) li
#footer #id:not(nav) li
Quote:
Originally Posted by LRRoberts0122 View Post
So basically when people use universal selectors as a reset (bad, but using it as an example), it would be: 0, 0, 0, 0
If someone is using a universal selector on an element, (*ul li {font-style: italic;}) it would be: 0, 0, 0, 0
If someone is using a universal selector on a class, (*.error p {color: red;}) it would be: 0, 0, 0, 1
The class is stronger... so *.error p.

Code:
* {}
*div { }
*.class { }
*#id {}
To be honest, none of this matters, you will probably never and shouldn't ever need to know which is stronger for these odd selectors.

Last edited by Sammy12; 10-01-2012 at 02:05 AM..
Sammy12 is offline   Reply With Quote
Old 10-01-2012, 02:45 PM   PM User | #3
quartzy
Regular Coder

 
Join Date: May 2009
Posts: 813
Thanks: 123
Thanked 24 Times in 24 Posts
quartzy is an unknown quantity at this point
I thought the id is stronger always! What do I know?
quartzy is offline   Reply With Quote
Old 10-01-2012, 09:52 PM   PM User | #4
Xherdas
New Coder

 
Join Date: Apr 2012
Posts: 44
Thanks: 0
Thanked 14 Times in 14 Posts
Xherdas is an unknown quantity at this point
In-line css overwrite id's. Unless !important is used.
Xherdas is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:42 PM.


Advertisement
Log in to turn off these ads.