We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    I’m currently redoing the css classes for my website, using ID to group together frequently used individual CSS classes.

    Let’s say I have...

    #content .heading
    #gameinfo .heading


    #gameinfo’s DIV ID would be inside the DIV ID for #content. Would #gameinfo’s .heading override #content’s, or would it inherit the CSS, and I would need to use a different name?
      My Snippets
      -> PopUpChunk v1.0
      • 33372
      • 1,611 Posts
      If #gameinfo is inside #content, then by definition anything in #gameinfo with a class of .heading is also inside #content, so yes it inherits those characteristics. You can override them any number of ways, but if the differences are substantial then personally I would just use another class. You can avoid the whole issue just by making the second class .subheading (or whatever).
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        #content .heading
        #content #gameinfo .heading

        would probably be the safest, as well as making it easier to see exactly what you’re working with.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 28033
          • 925 Posts
          Thanks for the expalanations. smiley
            My Snippets
            -> PopUpChunk v1.0
            • 4639
            • 36 Posts
            You may want to read How specificity works (sitepoint.com) in CSS.
              • 6726
              • 7,075 Posts
              Quote from: sottwell at Apr 26, 2008, 11:53 AM

              #content .heading
              #content #gameinfo .heading

              would probably be the safest, as well as making it easier to see exactly what you’re working with.

              Not only is it safer, but I have read articles stating that it’s also parsed faster by browsers...
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
                • 28033
                • 925 Posts
                Quote from: davidm at Apr 28, 2008, 11:10 AM

                Quote from: sottwell at Apr 26, 2008, 11:53 AM

                #content .heading
                #content #gameinfo .heading

                would probably be the safest, as well as making it easier to see exactly what you’re working with.

                Not only is it safer, but I have read articles stating that it’s also parsed faster by browsers...

                Just to check, #content #gameinfo .heading means that the CSS only applies if the div/whatever is inside both of those DIV ID tags, right?
                  My Snippets
                  -> PopUpChunk v1.0
                  • 7231
                  • 4,205 Posts
                  Yes. But IDs are not exclusive to DIVs, any element could have an ID.
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don't know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Right. What that’s saying is "the element with the class of "heading" that is inside of the element with the ID of gameinfo which is inside of the element with the ID of content". So if you had #sidebar #gameinfo .heading, it would not be affected by the #content #gameinfo .heading style (unless the #sidebar container happens to be inside of the #content container...)

                    What you are dealing with here is "specificity"

                    The more specific a selector, the more preference it receives when rendering a page. Actually, there are rules for calculating an item’s specificity. Basically, numeric values are assigned to certain CSS selectors. Every id selector has a value of 100; class selectors have a value of 10 and every HTML selector is assigned a value of 1. You add up these values for CSS rules and the higher number wins. The following calculations are made on the previous example:

                    * BODY H1 consists of two HTML selectors, so it is 1 + 1 = 2.
                    * H1 consists of one HTML selector, so the result is 1.
                    * In every instance, 2 > 1, so H1 elements (within BODY elements) are red.
                    http://articles.techrepublic.com.com/5100-3513-6164216.html
                    http://www.w3.org/TR/REC-CSS2/cascade.html
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 28033
                      • 925 Posts
                      I get it now. smiley

                      (I’m new to ID’s in CSS, so it was kinda confusing at first. You guys did a good job explaining it.)
                        My Snippets
                        -> PopUpChunk v1.0