CSS Specificity - External Stylesheet vs Internal Stylesheet using just classes












0















I have two CSS classes on one HTML element: .c-headline-1 and .c-hero__headline. In my external stylesheet, I'm using .c-headline-1 and in an internal stylesheet (<style type="text/css">) I'm using .hero__headline, but for some reason the .c-headline-1 property values are overwriting some of .hero__headline's property values. For example, if both have a font size declaration, .c-headline-1 is behaving as if it has higher specificity since it's overwriting .c-hero__headline's font size.



I thought internal stylesheets had higher specificity than external stylesheets or no?










share|improve this question



























    0















    I have two CSS classes on one HTML element: .c-headline-1 and .c-hero__headline. In my external stylesheet, I'm using .c-headline-1 and in an internal stylesheet (<style type="text/css">) I'm using .hero__headline, but for some reason the .c-headline-1 property values are overwriting some of .hero__headline's property values. For example, if both have a font size declaration, .c-headline-1 is behaving as if it has higher specificity since it's overwriting .c-hero__headline's font size.



    I thought internal stylesheets had higher specificity than external stylesheets or no?










    share|improve this question

























      0












      0








      0








      I have two CSS classes on one HTML element: .c-headline-1 and .c-hero__headline. In my external stylesheet, I'm using .c-headline-1 and in an internal stylesheet (<style type="text/css">) I'm using .hero__headline, but for some reason the .c-headline-1 property values are overwriting some of .hero__headline's property values. For example, if both have a font size declaration, .c-headline-1 is behaving as if it has higher specificity since it's overwriting .c-hero__headline's font size.



      I thought internal stylesheets had higher specificity than external stylesheets or no?










      share|improve this question














      I have two CSS classes on one HTML element: .c-headline-1 and .c-hero__headline. In my external stylesheet, I'm using .c-headline-1 and in an internal stylesheet (<style type="text/css">) I'm using .hero__headline, but for some reason the .c-headline-1 property values are overwriting some of .hero__headline's property values. For example, if both have a font size declaration, .c-headline-1 is behaving as if it has higher specificity since it's overwriting .c-hero__headline's font size.



      I thought internal stylesheets had higher specificity than external stylesheets or no?







      css css-specificity






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 29 '18 at 9:20









      bhoodbhood

      90211




      90211
























          3 Answers
          3






          active

          oldest

          votes


















          1














          All stylesheets are treated the same, what's important is the order in which the styles are declared. For visualization, imagine it this way: The browser takes all CSS files and combines it in one big css file (in the order that they appear in the source code). Then it should be clear why a style is getting overridden if you know how specifications in CSS work.






          share|improve this answer
























          • Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

            – bhood
            Aug 29 '18 at 12:15



















          1














          External and internal style sheets (in the head section) are assigned the same level of priority (inferior to the inline style priority though), the highest priority then is given according to their declaration order



          The last one declared gets the highest priority





          Ultimately the order is the following




          1. Inline style (inside an HTML element)

          2. External and internal style sheets (in the head section) --> The last one defined (internal or external) has the highest priority

          3. Browser default


          To learn more you can check the Cascading Order section of this page
          https://www.w3schools.com/css/css_howto.asp






          share|improve this answer































            0














            Are you sure that the order is important? Isn't it first a priority order where number one is the most significant and its styling will be applied first.




            1. Inline styling

            2. Internal stylesheets (style withing head element)

            3. External stylesheets (link href="style.css" etc.)


            Please correct me if I'm wrong.






            share|improve this answer
























            • You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

              – Alohci
              Aug 29 '18 at 11:39













            • @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

              – bhood
              Aug 29 '18 at 12:13












            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52073885%2fcss-specificity-external-stylesheet-vs-internal-stylesheet-using-just-classes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            All stylesheets are treated the same, what's important is the order in which the styles are declared. For visualization, imagine it this way: The browser takes all CSS files and combines it in one big css file (in the order that they appear in the source code). Then it should be clear why a style is getting overridden if you know how specifications in CSS work.






            share|improve this answer
























            • Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

              – bhood
              Aug 29 '18 at 12:15
















            1














            All stylesheets are treated the same, what's important is the order in which the styles are declared. For visualization, imagine it this way: The browser takes all CSS files and combines it in one big css file (in the order that they appear in the source code). Then it should be clear why a style is getting overridden if you know how specifications in CSS work.






            share|improve this answer
























            • Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

              – bhood
              Aug 29 '18 at 12:15














            1












            1








            1







            All stylesheets are treated the same, what's important is the order in which the styles are declared. For visualization, imagine it this way: The browser takes all CSS files and combines it in one big css file (in the order that they appear in the source code). Then it should be clear why a style is getting overridden if you know how specifications in CSS work.






            share|improve this answer













            All stylesheets are treated the same, what's important is the order in which the styles are declared. For visualization, imagine it this way: The browser takes all CSS files and combines it in one big css file (in the order that they appear in the source code). Then it should be clear why a style is getting overridden if you know how specifications in CSS work.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Aug 29 '18 at 9:30









            clonedcloned

            64768




            64768













            • Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

              – bhood
              Aug 29 '18 at 12:15



















            • Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

              – bhood
              Aug 29 '18 at 12:15

















            Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

            – bhood
            Aug 29 '18 at 12:15





            Thanks @cloned here's MDN reference confirming your answer: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

            – bhood
            Aug 29 '18 at 12:15













            1














            External and internal style sheets (in the head section) are assigned the same level of priority (inferior to the inline style priority though), the highest priority then is given according to their declaration order



            The last one declared gets the highest priority





            Ultimately the order is the following




            1. Inline style (inside an HTML element)

            2. External and internal style sheets (in the head section) --> The last one defined (internal or external) has the highest priority

            3. Browser default


            To learn more you can check the Cascading Order section of this page
            https://www.w3schools.com/css/css_howto.asp






            share|improve this answer




























              1














              External and internal style sheets (in the head section) are assigned the same level of priority (inferior to the inline style priority though), the highest priority then is given according to their declaration order



              The last one declared gets the highest priority





              Ultimately the order is the following




              1. Inline style (inside an HTML element)

              2. External and internal style sheets (in the head section) --> The last one defined (internal or external) has the highest priority

              3. Browser default


              To learn more you can check the Cascading Order section of this page
              https://www.w3schools.com/css/css_howto.asp






              share|improve this answer


























                1












                1








                1







                External and internal style sheets (in the head section) are assigned the same level of priority (inferior to the inline style priority though), the highest priority then is given according to their declaration order



                The last one declared gets the highest priority





                Ultimately the order is the following




                1. Inline style (inside an HTML element)

                2. External and internal style sheets (in the head section) --> The last one defined (internal or external) has the highest priority

                3. Browser default


                To learn more you can check the Cascading Order section of this page
                https://www.w3schools.com/css/css_howto.asp






                share|improve this answer













                External and internal style sheets (in the head section) are assigned the same level of priority (inferior to the inline style priority though), the highest priority then is given according to their declaration order



                The last one declared gets the highest priority





                Ultimately the order is the following




                1. Inline style (inside an HTML element)

                2. External and internal style sheets (in the head section) --> The last one defined (internal or external) has the highest priority

                3. Browser default


                To learn more you can check the Cascading Order section of this page
                https://www.w3schools.com/css/css_howto.asp







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 18:45









                LorenzoLorenzo

                1112




                1112























                    0














                    Are you sure that the order is important? Isn't it first a priority order where number one is the most significant and its styling will be applied first.




                    1. Inline styling

                    2. Internal stylesheets (style withing head element)

                    3. External stylesheets (link href="style.css" etc.)


                    Please correct me if I'm wrong.






                    share|improve this answer
























                    • You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                      – Alohci
                      Aug 29 '18 at 11:39













                    • @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                      – bhood
                      Aug 29 '18 at 12:13
















                    0














                    Are you sure that the order is important? Isn't it first a priority order where number one is the most significant and its styling will be applied first.




                    1. Inline styling

                    2. Internal stylesheets (style withing head element)

                    3. External stylesheets (link href="style.css" etc.)


                    Please correct me if I'm wrong.






                    share|improve this answer
























                    • You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                      – Alohci
                      Aug 29 '18 at 11:39













                    • @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                      – bhood
                      Aug 29 '18 at 12:13














                    0












                    0








                    0







                    Are you sure that the order is important? Isn't it first a priority order where number one is the most significant and its styling will be applied first.




                    1. Inline styling

                    2. Internal stylesheets (style withing head element)

                    3. External stylesheets (link href="style.css" etc.)


                    Please correct me if I'm wrong.






                    share|improve this answer













                    Are you sure that the order is important? Isn't it first a priority order where number one is the most significant and its styling will be applied first.




                    1. Inline styling

                    2. Internal stylesheets (style withing head element)

                    3. External stylesheets (link href="style.css" etc.)


                    Please correct me if I'm wrong.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Aug 29 '18 at 10:47









                    TimpaninhoTimpaninho

                    13




                    13













                    • You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                      – Alohci
                      Aug 29 '18 at 11:39













                    • @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                      – bhood
                      Aug 29 '18 at 12:13



















                    • You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                      – Alohci
                      Aug 29 '18 at 11:39













                    • @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                      – bhood
                      Aug 29 '18 at 12:13

















                    You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                    – Alohci
                    Aug 29 '18 at 11:39







                    You're wrong. Internal and external stylesheets have equal priority. Thanks to MDN among others, the notion that they had different priorities became a widely held misunderstanding.

                    – Alohci
                    Aug 29 '18 at 11:39















                    @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                    – bhood
                    Aug 29 '18 at 12:13





                    @Alohci is correct: internal and external stylesheets have equal priority. Here's the MDN reference: developer.mozilla.org/en-US/docs/Web/HTML/Element/style

                    – bhood
                    Aug 29 '18 at 12:13


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52073885%2fcss-specificity-external-stylesheet-vs-internal-stylesheet-using-just-classes%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    MongoDB - Not Authorized To Execute Command

                    How to fix TextFormField cause rebuild widget in Flutter

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith