How to remove an underline on a pseudo-element?

前端 未结 3 570
南笙
南笙 2020-12-30 07:34

On Chrome and Firefox, if I apply a text-decoration:underline on a tag, by default the underline does not apply to the pseudo element. But on IE it does, and I can\'t remove

相关标签:
3条回答
  • 2020-12-30 08:12

    As text-decoration: underline; can't be overridden in IE you could use border-bottom: 1px solid green; instead. This can then be overwritten on the :before by setting its border colour to the background colour (in this case white). This will only work on solid colour backgrounds though.

    a {		
      color: green;
      display: inline-block;
      padding-left: 9px;
      position: relative;
      text-decoration: none;
    }
    a:before {
      content: '\203A\00a0';
      display: inline-block;
      left: 0;
      position: absolute;
      top: 0;
    }
    a:hover {
      border-bottom: 1px solid green;
    }
    a:hover:before {
      border-bottom: 1px solid white;
    }
    <a href="#" id="underline">Hover to check underline</a>

    0 讨论(0)
  • 2020-12-30 08:14

    you can add this to your css. this helped me in the IE

    a {text-decoration:none;}
    a:hover {text-decoration:underline;}
    a:before,a:after { text-decoration:underline;}
    a:before,a:after,
    a:hover:before,a:hover:after {text-decoration:none;}
    
    0 讨论(0)
  • 2020-12-30 08:19

    It seems that IE don't let you override the text-decoration in the pseudoelement if it isn't set in it. First let the pseudo-element be underlined - text-decoration: underline - and afterwards override this with textdecoration: none.

    #underline:hover:before
    {
    	text-decoration:underline;
    }
    
    #underline:hover:before
    {
    	text-decoration:none;
    }

    0 讨论(0)
提交回复
热议问题