How do I not underline an element in a link?












7















I am trying to underline the link except for the #myspan element, which I do not want underlined under any circumstance. I'd like to also change #myspan's color. The rules don't seem to apply to it. If I reverse the order and not underline the "a" but underline #myspan it seems to apply the rules. I've seen Text decoration for link and span inside this link to no avail.






    a {
text-decoration: underline;
}

a #myspan {
color: black;
text-decoration: none;
}

a:active #myspan {
color: grey;
text-decoration: none;
}

a:visited #myspan {
color: yellow;
text-decoration: none;
}

a:hover #myspan {
color: red;
text-decoration: none;
}

  <a href="#">A link <span id="myspan">some additional information</span></a>












share|improve this question





























    7















    I am trying to underline the link except for the #myspan element, which I do not want underlined under any circumstance. I'd like to also change #myspan's color. The rules don't seem to apply to it. If I reverse the order and not underline the "a" but underline #myspan it seems to apply the rules. I've seen Text decoration for link and span inside this link to no avail.






        a {
    text-decoration: underline;
    }

    a #myspan {
    color: black;
    text-decoration: none;
    }

    a:active #myspan {
    color: grey;
    text-decoration: none;
    }

    a:visited #myspan {
    color: yellow;
    text-decoration: none;
    }

    a:hover #myspan {
    color: red;
    text-decoration: none;
    }

      <a href="#">A link <span id="myspan">some additional information</span></a>












    share|improve this question



























      7












      7








      7


      1






      I am trying to underline the link except for the #myspan element, which I do not want underlined under any circumstance. I'd like to also change #myspan's color. The rules don't seem to apply to it. If I reverse the order and not underline the "a" but underline #myspan it seems to apply the rules. I've seen Text decoration for link and span inside this link to no avail.






          a {
      text-decoration: underline;
      }

      a #myspan {
      color: black;
      text-decoration: none;
      }

      a:active #myspan {
      color: grey;
      text-decoration: none;
      }

      a:visited #myspan {
      color: yellow;
      text-decoration: none;
      }

      a:hover #myspan {
      color: red;
      text-decoration: none;
      }

        <a href="#">A link <span id="myspan">some additional information</span></a>












      share|improve this question
















      I am trying to underline the link except for the #myspan element, which I do not want underlined under any circumstance. I'd like to also change #myspan's color. The rules don't seem to apply to it. If I reverse the order and not underline the "a" but underline #myspan it seems to apply the rules. I've seen Text decoration for link and span inside this link to no avail.






          a {
      text-decoration: underline;
      }

      a #myspan {
      color: black;
      text-decoration: none;
      }

      a:active #myspan {
      color: grey;
      text-decoration: none;
      }

      a:visited #myspan {
      color: yellow;
      text-decoration: none;
      }

      a:hover #myspan {
      color: red;
      text-decoration: none;
      }

        <a href="#">A link <span id="myspan">some additional information</span></a>








          a {
      text-decoration: underline;
      }

      a #myspan {
      color: black;
      text-decoration: none;
      }

      a:active #myspan {
      color: grey;
      text-decoration: none;
      }

      a:visited #myspan {
      color: yellow;
      text-decoration: none;
      }

      a:hover #myspan {
      color: red;
      text-decoration: none;
      }

        <a href="#">A link <span id="myspan">some additional information</span></a>





          a {
      text-decoration: underline;
      }

      a #myspan {
      color: black;
      text-decoration: none;
      }

      a:active #myspan {
      color: grey;
      text-decoration: none;
      }

      a:visited #myspan {
      color: yellow;
      text-decoration: none;
      }

      a:hover #myspan {
      color: red;
      text-decoration: none;
      }

        <a href="#">A link <span id="myspan">some additional information</span></a>






      html css






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago









      soulshined

      5,03642248




      5,03642248










      asked 4 hours ago









      Marissa LevyMarissa Levy

      2721652103




      2721652103
























          3 Answers
          3






          active

          oldest

          votes


















          6














          Make the element to be inline-block and it won't get affected by the underline:






          a {
          text-decoration: underline;
          }

          a #myspan {
          color: black;
          display:inline-block;
          }

          a:active #myspan {
          color: grey;
          }

          a:visited #myspan {
          color: yellow;
          }

          a:hover #myspan {
          color: red;
          }

          <a href="#">A link <span id="myspan">some additional information</span></a>






          Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. ref






          To remove the small space between text and span you can get rid of the whitespace and use a small margin:






          a {
          text-decoration: underline;
          }

          a #myspan {
          color: black;
          display:inline-block;
          margin-left:4px;
          }


          a:active #myspan {
          color: grey;
          }

          a:visited #myspan {
          color: yellow;
          }

          a:hover #myspan {
          color: red;
          }

          <a href="#">A link<span id="myspan">some additional information</span></a>








          share|improve this answer





















          • 1





            just learned something new. +1 Never had a reason to know this before today though.

            – soulshined
            4 hours ago



















          3














          I made a:hover #myspan, a:hover






          a {
          text-decoration: underline;
          }

          a #myspan {
          color: black;
          text-decoration: none;
          }

          a:active #myspan {
          color: grey;
          text-decoration: none;
          }

          a:visited #myspan {
          color: yellow;
          text-decoration: none;
          }

          a:hover #myspan, a:hover {
          color: red;
          text-decoration: none;
          }

          <a href="#">A link <span id="myspan">some additional information</span></a>








          share|improve this answer
























          • dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

            – soulshined
            4 hours ago













          • oops. The answer is given below. I misunderstood.

            – Dogukan Cavus
            4 hours ago













          • been there done that. just a quick edit is needed

            – soulshined
            4 hours ago



















          1














          a {
          text-decoration: none;
          }

          #span1{
          text-decoration:underline;
          }

          #myspan {
          color: black;
          text-decoration: none!important;

          }

          a:active #myspan {
          color: grey;
          text-decoration: none;
          }

          a:visited #myspan {
          color: yellow;
          text-decoration: none;
          }

          a:hover #myspan {
          color: red;
          text-decoration: none;
          }


          Make the above changes to the css.



          <a href="#"><span id="span1">A link </span><span id="myspan">some additional information</span></a>


          Make the changes to HTML.



          Let me know if it works






          share|improve this answer

























            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%2f54816830%2fhow-do-i-not-underline-an-element-in-a-link%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









            6














            Make the element to be inline-block and it won't get affected by the underline:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>






            Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. ref






            To remove the small space between text and span you can get rid of the whitespace and use a small margin:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>








            share|improve this answer





















            • 1





              just learned something new. +1 Never had a reason to know this before today though.

              – soulshined
              4 hours ago
















            6














            Make the element to be inline-block and it won't get affected by the underline:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>






            Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. ref






            To remove the small space between text and span you can get rid of the whitespace and use a small margin:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>








            share|improve this answer





















            • 1





              just learned something new. +1 Never had a reason to know this before today though.

              – soulshined
              4 hours ago














            6












            6








            6







            Make the element to be inline-block and it won't get affected by the underline:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>






            Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. ref






            To remove the small space between text and span you can get rid of the whitespace and use a small margin:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>








            share|improve this answer















            Make the element to be inline-block and it won't get affected by the underline:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>






            Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables. ref






            To remove the small space between text and span you can get rid of the whitespace and use a small margin:






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>








            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>





            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            }

            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>





            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>





            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            display:inline-block;
            margin-left:4px;
            }


            a:active #myspan {
            color: grey;
            }

            a:visited #myspan {
            color: yellow;
            }

            a:hover #myspan {
            color: red;
            }

            <a href="#">A link<span id="myspan">some additional information</span></a>






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 4 hours ago

























            answered 4 hours ago









            Temani AfifTemani Afif

            74.5k94386




            74.5k94386








            • 1





              just learned something new. +1 Never had a reason to know this before today though.

              – soulshined
              4 hours ago














            • 1





              just learned something new. +1 Never had a reason to know this before today though.

              – soulshined
              4 hours ago








            1




            1





            just learned something new. +1 Never had a reason to know this before today though.

            – soulshined
            4 hours ago





            just learned something new. +1 Never had a reason to know this before today though.

            – soulshined
            4 hours ago













            3














            I made a:hover #myspan, a:hover






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>








            share|improve this answer
























            • dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

              – soulshined
              4 hours ago













            • oops. The answer is given below. I misunderstood.

              – Dogukan Cavus
              4 hours ago













            • been there done that. just a quick edit is needed

              – soulshined
              4 hours ago
















            3














            I made a:hover #myspan, a:hover






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>








            share|improve this answer
























            • dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

              – soulshined
              4 hours ago













            • oops. The answer is given below. I misunderstood.

              – Dogukan Cavus
              4 hours ago













            • been there done that. just a quick edit is needed

              – soulshined
              4 hours ago














            3












            3








            3







            I made a:hover #myspan, a:hover






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>








            share|improve this answer













            I made a:hover #myspan, a:hover






            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>








            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>





            a {
            text-decoration: underline;
            }

            a #myspan {
            color: black;
            text-decoration: none;
            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan, a:hover {
            color: red;
            text-decoration: none;
            }

            <a href="#">A link <span id="myspan">some additional information</span></a>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 4 hours ago









            Dogukan CavusDogukan Cavus

            3,5312627




            3,5312627













            • dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

              – soulshined
              4 hours ago













            • oops. The answer is given below. I misunderstood.

              – Dogukan Cavus
              4 hours ago













            • been there done that. just a quick edit is needed

              – soulshined
              4 hours ago



















            • dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

              – soulshined
              4 hours ago













            • oops. The answer is given below. I misunderstood.

              – Dogukan Cavus
              4 hours ago













            • been there done that. just a quick edit is needed

              – soulshined
              4 hours ago

















            dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

            – soulshined
            4 hours ago







            dont think OP wants the span underlined under any conditions. underline the link except for the #myspan element

            – soulshined
            4 hours ago















            oops. The answer is given below. I misunderstood.

            – Dogukan Cavus
            4 hours ago







            oops. The answer is given below. I misunderstood.

            – Dogukan Cavus
            4 hours ago















            been there done that. just a quick edit is needed

            – soulshined
            4 hours ago





            been there done that. just a quick edit is needed

            – soulshined
            4 hours ago











            1














            a {
            text-decoration: none;
            }

            #span1{
            text-decoration:underline;
            }

            #myspan {
            color: black;
            text-decoration: none!important;

            }

            a:active #myspan {
            color: grey;
            text-decoration: none;
            }

            a:visited #myspan {
            color: yellow;
            text-decoration: none;
            }

            a:hover #myspan {
            color: red;
            text-decoration: none;
            }


            Make the above changes to the css.



            <a href="#"><span id="span1">A link </span><span id="myspan">some additional information</span></a>


            Make the changes to HTML.



            Let me know if it works






            share|improve this answer






























              1














              a {
              text-decoration: none;
              }

              #span1{
              text-decoration:underline;
              }

              #myspan {
              color: black;
              text-decoration: none!important;

              }

              a:active #myspan {
              color: grey;
              text-decoration: none;
              }

              a:visited #myspan {
              color: yellow;
              text-decoration: none;
              }

              a:hover #myspan {
              color: red;
              text-decoration: none;
              }


              Make the above changes to the css.



              <a href="#"><span id="span1">A link </span><span id="myspan">some additional information</span></a>


              Make the changes to HTML.



              Let me know if it works






              share|improve this answer




























                1












                1








                1







                a {
                text-decoration: none;
                }

                #span1{
                text-decoration:underline;
                }

                #myspan {
                color: black;
                text-decoration: none!important;

                }

                a:active #myspan {
                color: grey;
                text-decoration: none;
                }

                a:visited #myspan {
                color: yellow;
                text-decoration: none;
                }

                a:hover #myspan {
                color: red;
                text-decoration: none;
                }


                Make the above changes to the css.



                <a href="#"><span id="span1">A link </span><span id="myspan">some additional information</span></a>


                Make the changes to HTML.



                Let me know if it works






                share|improve this answer















                a {
                text-decoration: none;
                }

                #span1{
                text-decoration:underline;
                }

                #myspan {
                color: black;
                text-decoration: none!important;

                }

                a:active #myspan {
                color: grey;
                text-decoration: none;
                }

                a:visited #myspan {
                color: yellow;
                text-decoration: none;
                }

                a:hover #myspan {
                color: red;
                text-decoration: none;
                }


                Make the above changes to the css.



                <a href="#"><span id="span1">A link </span><span id="myspan">some additional information</span></a>


                Make the changes to HTML.



                Let me know if it works







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 3 hours ago

























                answered 3 hours ago









                SrijanSrijan

                314




                314






























                    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%2f54816830%2fhow-do-i-not-underline-an-element-in-a-link%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

                    What are all the squawk codes?

                    What are differences between VBoxVGA, VMSVGA and VBoxSVGA in VirtualBox?

                    Hudsonelva