Html 如何更改 Bootstrap 禁用按钮的颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35818064/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change color of Bootstrap disabled button?
提问by Oliver Beck
I am using a bootstrap button on a page of my website and I want to change the color of a disabled button. A button that is "grayed out" and you cannot click. Is there a way I can change the color of this using CSS? Any class for this?
我在我的网站页面上使用引导按钮,我想更改禁用按钮的颜色。一个“变灰”的按钮,您无法点击。有没有办法可以使用 CSS 更改它的颜色?有没有这方面的课?
Thank you very much!
非常感谢!
回答by Jumpa
In case your button look like this:
如果您的按钮如下所示:
<button class="btn btn-primary" disabled>Button</button>
the next CSS code will change its color (when disabled only):
下一个 CSS 代码将更改其颜色(仅在禁用时):
.btn.btn-primary[disabled] {
background-color: #00ff00;
}
or
或者
.btn.btn-primary:disabled{
background-color: #00ff00;
}
回答by Graphicoding
If I understand your question correctly; you need to use :disabled
.
Here is a working code:
如果我正确理解你的问题;你需要使用:disabled
. 这是一个工作代码:
#work {
width: 200px;
height: 50px;
color: black;
}
#work:disabled{
background-color: red;
}
<button id="work"disabled="true" type="submit">Button </button>
回答by jeffkenn
I had to do this because I was disabling the button in javascript.
我必须这样做,因为我禁用了 javascript 中的按钮。
var button = document.querySelector("#button");
button.disabled = 'disabled';
button.setAttribute("style", "background-color: #799b48");