Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a CSS Hover not work if a button is disabled?

Tags:

css

I have this CSS:

html.darkBlue .btn1 button:hover:not(.nohover) {
  background: #0007d5;
  border: 1px solid #0007d5;
  color: white;
}

I am rather confused about disabled. How can I make it so that this CSS does not work if the button is disabled?

like image 572
Samantha J T Star Avatar asked Jan 05 '14 11:01

Samantha J T Star


People also ask

Does hover work on disabled button?

Just like other pseudo-class selectors, the :disabled selector can be chained with other selectors such as :hover , for example, to provide hover styles for disabled elements.

How do I disable a button in CSS?

To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.

How do I enable hover in CSS?

The :hover selector is used to select elements when you mouse over them. Tip: The :hover selector can be used on all elements, not only on links. Tip: Use the :link selector to style links to unvisited pages, the :visited selector to style links to visited pages, and the :active selector to style the active link.


2 Answers

If you don't need to support IE < 9 you could use the :enabled pseudo class.

html.darkBlue .btn1 button:hover:enabled {
    background: #0007d5;
    border: 1px solid #0007d5;
    color: white;
}
like image 168
Lars Beck Avatar answered Sep 19 '22 14:09

Lars Beck


Try with (demo http://jsfiddle.net/JDNLk/)

HTML

<button class="btn1" disabled="disabled">disabled</button>
<button class="btn1">enabled</button>

CSS

html.darkBlue .btn1 button:hover:not([enabled="enabled"]) {
  background: #0007d5;
  border: 1px solid #0007d5;
  color: white;   
}
like image 41
user2314737 Avatar answered Sep 20 '22 14:09

user2314737