Hover and Active only when not disabled

后端 未结 7 2054
长情又很酷
长情又很酷 2020-12-22 21:29

I use hover, active and disabled to style Buttons.

But the problem is when the button is disabled the hover and ac

7条回答
  •  天涯浪人
    2020-12-22 22:03

    A lower-specificity approach that works in most modern browsers (IE11+, and excluding some mobile Opera & IE browsers -- http://caniuse.com/#feat=pointer-events):

    .btn {
      /* base styles */
    }
    
    .btn[disabled]
      opacity: 0.4;
      cursor: default;
      pointer-events: none;
    }
    
    .btn:hover {
      color: red;
    }
    

    The pointer-events: none rule will disable hover; you won't need to raise specificity with a .btn[disabled]:hover selector to nullify the hover style.

    (FYI, this is the simple HTML pointer-events, not the contentious abstracting-input-devices pointer-events)

提交回复
热议问题