Remove underline only from anchor element child

前端 未结 7 777
故里飘歌
故里飘歌 2020-12-10 12:02

When an a tag contains child elements, like an i tag, it\'s still applying the underline to it on hover, and I\'m wondering how to remove the under

相关标签:
7条回答
  • 2020-12-10 12:27

    Try following css,

    a:hover i{
        display: inline-block; <-- this is the trick
        text-decoration:none !important;
    }
    

    Demo

    0 讨论(0)
  • 2020-12-10 12:30

    I had the same issue and fixed this using the following css rule:

    a:-webkit-any-link {text-decoration:none}
    

    hope it helps!

    0 讨论(0)
  • 2020-12-10 12:32

    Set the display property of i to inline-block:

    a i {
        ...
        display: inline-block;
    }
    

    JSFiddle

    0 讨论(0)
  • 2020-12-10 12:37

    Simply add display:inline-block;

    FIDDLE DEMO

    a:hover i {
        display:inline-block;
        text-decoration:none !important;
    }
    
    0 讨论(0)
  • 2020-12-10 12:38

    You can also write you HTML like

        <a href="#">Link</a><i>(2)</i>
    

    and CSS like

      a{
        display:inline-block;
        text-decoration:none;
      }
    
    0 讨论(0)
  • 2020-12-10 12:38

    I faced the same problem.

    But I wanted the inner element to be Right, so setting just float: right worked fine.

    a {
        display: block;
        overflow: hidden; // Clearfix
        text-decoration: none;
    }
    a .right-none-underline-element { float: right }
    

    For your reference.

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