简体   繁体   English

如果使用CSS悬停,如何使我的禁用按钮不会改变颜色?

[英]How can I make my disabled button not change color when there's a hover with CSS?

I tried this CSS: 我试过这个CSS:

html.dark .btn:hover:not(disabled),
html.dark .btn:focus {
  color: #ffffff;
  background-color: #222222;
  *background-color: #151515;
}
html.dark .btn.disabled,
html.dark .btn[disabled] {
  color: red;
  background-color: #222222;
  *background-color: #151515;
}

But still when I hover over the button I see the color change from red to white. 但是当我将鼠标悬停在按钮上时,我看到颜色从红色变为白色。 Note that it's correctly picking up the fact it's disabled. 请注意,它正确地发现了它被禁用的事实。 I am using: 我在用:

disabled="disabled"

in my button. 在我的按钮。

Try .btn:hover:not(:disabled), 试试.btn:hover:not(:disabled),

A small example 一个小例子

Your example didn't work because you are using .btn:hover:not(disabled) you have to use a pseudo class to achieve what you need reference pseudo classes 您的示例无效,因为您正在使用.btn:hover:not(disabled)您必须使用伪类来实现您需要的引用伪类

 button:hover:not(:disabled){ color:red; } 
 <button>Not disabled</button> <button disabled>disabled</button> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何指定未禁用的CSS标记并将鼠标悬停在按钮上? - How can I specify a CSS tag for not disabled and hover on a button? 当 ion-tab-button 处于活动状态时,如何更改图标的颜色? CSS 离子 - How can i change the color of my icon when ion-tab-button is active? CSS Ionic 仅当单击CSS时,如何才能更改按钮的颜色? - How can I change the color of a button with CSS only when it is clicked? 如何使这种悬停效果(悬停1按钮更改元素的ID,然后在悬停时将其更改回其原始ID?)[jquery,css3] - How do I make this hover effect (hover 1 button to change an element's ID then when hovered-out it changes back to it's original ID?) [jquery,css3] 如何更改悬停颜色css按钮 - How to change hover color css button 当它位于div标签中时,如何使用CSS更改链接颜色和背景悬停? - How do I change the link color and background hover with css when it's inside a div tag? 如何在悬停时使用CSS更改选择选项的颜色? - How can I change color of a select option with CSS on hover? 如何使用 CSS 将默认 Bootstrap 按钮颜色更改为我自己选择的自定义颜色? - How can i change the default Bootstrap button color to my own choice of custom color by using CSS? 如何在悬停列表中更改下拉菜单的颜色? - How can I change the color of my dropdown inside a list on hover? 如何才能使UX菜单的CSS菜单悬停状态水平移动? - How can I make my CSS menu's hover states move horizontally for UX purposes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM