CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   HTML & CSS (http://www.codingforums.com/forumdisplay.php?f=13)
-   -   CSS: Specificity (http://www.codingforums.com/showthread.php?t=274781)

LRRoberts0122 09-30-2012 08:01 PM

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! :)

Sammy12 10-01-2012 01:53 AM

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 (Post 1275018)
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.

quartzy 10-01-2012 02:45 PM

I thought the id is stronger always! What do I know?

Xherdas 10-01-2012 09:52 PM

In-line css overwrite id's. Unless !important is used.


All times are GMT +1. The time now is 08:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.