How can I exclude a specific element from inheriting CSS rules?

前端 未结 2 532
春和景丽
春和景丽 2020-12-25 12:29

I have this CSS:

a {
  color:#19558D;
  padding:3px 5px;
  text-decoration:none;
}

a:hover {
  background-color:#D1E1EA;
  color:#19558D;
  text-decoration:         


        
相关标签:
2条回答
  • 2020-12-25 12:40

    You can apply your own class or inline style to the link in question.

    for example:

    <a href="#" class="MyNewClass" />
    

    or

    <a href="#" style="color:red;" />
    
    0 讨论(0)
  • 2020-12-25 12:53

    There are two ways you can do this.

    First way is to use the :not() selector and give your link that you don't want the styles applied to class:

    a:not(.unstyled):hover {
      background-color:#D1E1EA;
      color:#19558D;
      text-decoration:none;
    }
    

    However, the :not() selector is not supported in IE8 or less, so the second option is to give your unstyled links a class, and override those properties for that link with that class:

    a.unstyled:hover {
      background-color:none;
      color:#000
      text-decoration:none;
    } 
    
    0 讨论(0)
提交回复
热议问题