Comments on: Specifics on CSS Specificity https://css-tricks.com/specifics-on-css-specificity/ Tips, Tricks, and Techniques on using Cascading Style Sheets. Wed, 20 Jan 2021 15:54:27 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Will Murray (Willscrlt) https://css-tricks.com/specifics-on-css-specificity/#comment-1411475 Sat, 22 Mar 2014 03:12:39 +0000 http://css-tricks.com/?p=855#comment-1411475 In reply to Will Murray (Willscrlt).

I found the issue. There is a @media selector above that covered the style I was trying to override. Therefore, I suppose that means that @media has a very high value, though I’m not exactly sure where it would fall into this hierarchy. Perhaps that information could be added to this article?

]]>
By: Will Murray (Willscrlt) https://css-tricks.com/specifics-on-css-specificity/#comment-1410251 Fri, 21 Mar 2014 23:58:39 +0000 http://css-tricks.com/?p=855#comment-1410251 Using the Bootstrap boilerplate from Initializr.com, there is a built-in style, which appears to have a specificity of 0,0,1,0:

.col-lg-4 {
        width: 33.33333333333333%;
    }

I wanted to give it rounded corners with a border (no problem) and give it a little room between columns so the borders don’t touch. I created this code, which to me seems to have a specificity of 0,0,2,0:

.col-lg-4.rounded {
        margin-right:0.5%;
        width: 32.83333333333333;
    }

According to Firebug, both selectors are considered, but the non-.rounded loses to the regular one. So, I tried creating the inverse, which to me seems to also have a specificity of 0,0,2,0:

.col-lg-4:not(.rounded) {
        width: 33.33333333333333%;
    }

Sure enough, it beats out the plain one, apparently because it has more specificity.
I also tried changing around the order of the selectors, inline vs. included, and the order the classes are listed (.rounded.col-lg-4), and nothing made a difference. I did my testing in Chrome.

So it makes me wonder why two classes on the same element along with a selector that targets both, not have higher specificity than a selector targeting only one? Or maybe my math is just wrong?

]]>
By: Dylan Archer https://css-tricks.com/specifics-on-css-specificity/#comment-760030 Thu, 05 Dec 2013 01:31:54 +0000 http://css-tricks.com/?p=855#comment-760030 In reply to Crazyturkish19.

!important applies to the element it is assigned to, not child elements. I believe <a> is considered a child of <p> in this case. Any text within the parent element would be red regardless of what styles were applied to the universal p selecter; However <a> would retain it’s specified styles.

]]>
By: Dylan Archer https://css-tricks.com/specifics-on-css-specificity/#comment-759917 Thu, 05 Dec 2013 00:51:26 +0000 http://css-tricks.com/?p=855#comment-759917 In reply to Christoph Zillgens.

I’m aware this post is old, but wanted to add useful information encase someone else read this comment in the future.

http://www.w3.org/TR/CSS2/cascade.html

6.4.2 !important rules

CSS attempts to create a balance of power between author and user style sheets. By default, rules in an author’s style sheet override those in a user’s style sheet (see cascade rule 3).

]]>
By: Crazyturkish19 https://css-tricks.com/specifics-on-css-specificity/#comment-714558 Wed, 27 Nov 2013 00:32:14 +0000 http://css-tricks.com/?p=855#comment-714558 I found your “!important” on specificity explanation little confusing. For example:

<style>
    .foo{ color:red!important;}
    a {color:green;}
</style>

<p class="foo">
       <a href="#">Foo</a> Bar
</p>

The color of “Foo” text in “a” will be green but most people might think it is red.

]]>
By: tzi https://css-tricks.com/specifics-on-css-specificity/#comment-683077 Wed, 20 Nov 2013 14:02:15 +0000 http://css-tricks.com/?p=855#comment-683077 Thanks for this article!

You reminded me that the universal selector has no specificity :)

I also use a different system when I want to share a specificity whit another developer.

]]>
By: Jennifer R https://css-tricks.com/specifics-on-css-specificity/#comment-77807 Sun, 13 Jun 2010 15:16:26 +0000 http://css-tricks.com/?p=855#comment-77807 I don’t like using the universal selector *, sometimes i lose the control of it and maybe other designers couldn’t understand my CSS code.

]]>
By: Will Fastie https://css-tricks.com/specifics-on-css-specificity/#comment-77764 Sat, 12 Jun 2010 13:56:36 +0000 http://css-tricks.com/?p=855#comment-77764 Specificity is one of the most confusing aspects of CSS. Your article is the best I’ve seen at explaining it, an excellent job.

I’m concerned about people finding this article. When I first stumbled on to the issue several years ago, I had no idea it was called “specificity.” I was simply trying to find out why styles attached to an id were overriding styles defined by class on an element contained within the id’ed element!

It would be very interesting to learn what people searched for when they were trying to get past this and then make sure the article was responsive to such searches.

]]>
By: Gwen https://css-tricks.com/specifics-on-css-specificity/#comment-77051 Tue, 01 Jun 2010 14:53:33 +0000 http://css-tricks.com/?p=855#comment-77051 Nice of you to update this. On the web these days, all I find is older, incorrect information. You are one of the short list of good websites on the net.

]]>
By: Resources - Tweets of the Week (5.17.10 - 5.21.10) | Think Design https://css-tricks.com/specifics-on-css-specificity/#comment-76459 Fri, 21 May 2010 21:43:38 +0000 http://css-tricks.com/?p=855#comment-76459 […] http://www.pantonehotel.com/ From @jeremyschultz   Tim Burton Posters From @ppd   # Specifics on CSS > Specificity | CSS-Tricks #css From @ronicadesign   Google Font Directory http://code.google.com/webfonts From […]

]]>
By: Emulating CSS Child Selectors in IE6 « Crafty Code https://css-tricks.com/specifics-on-css-specificity/#comment-76313 Wed, 19 May 2010 16:15:30 +0000 http://css-tricks.com/?p=855#comment-76313 […] that the specificity of the two selectors is the same. This helps to prevent the “clearing” selector from […]

]]>
By: Ramm https://css-tricks.com/specifics-on-css-specificity/#comment-76050 Fri, 14 May 2010 19:53:26 +0000 http://css-tricks.com/?p=855#comment-76050 Interesting way to calculate that. Many times i ended putting “!important” instead of try to find out what was wrong.

]]>
By: Jason https://css-tricks.com/specifics-on-css-specificity/#comment-76030 Fri, 14 May 2010 04:36:28 +0000 http://css-tricks.com/?p=855#comment-76030 This is one of my favorite articles about CSS specificity. I never really was able to really understand what this was all about even when I was going to school The teachers I had didn’t really explain it all that well. It is amazing that CSS really is all that powerful. I don’t even know anything about CSS5 so I have a long ways to go.

]]>
By: Patrick https://css-tricks.com/specifics-on-css-specificity/#comment-75915 Wed, 12 May 2010 15:00:43 +0000 http://css-tricks.com/?p=855#comment-75915 Well done, dude! really nice drawings *g*

]]>
By: Miller Medeiros https://css-tricks.com/specifics-on-css-specificity/#comment-75911 Wed, 12 May 2010 14:43:41 +0000 http://css-tricks.com/?p=855#comment-75911 One good reminder is to avoid being more specific than you need, sometimes it can help performance and also makes maintenance/re-use easier. You don’t need the “ul” on “ul#summer-drinks” since you can only have one ID per page.. having less and more efficient selectors make your page render faster.

Another thing is to always put elements (e.g. “p, a, h1”) and generic classes (e.g. “last”) before the other rules, it’s easier to understand what will be overwritten..

]]>