2023-12-10 05:00:01

样式禁用按钮与CSS

我试图改变一个按钮的风格与一个嵌入的图像,如下图所示:

http://jsfiddle.net/krishnathota/xzBaZ/1/

在这个例子中,恐怕没有图像。

我试着:

当按钮被禁用时更改按钮的背景颜色 当按钮被禁用时,更改按钮中的图像 禁用悬停效果时禁用 当您在按钮中单击图像并拖动它时,可以单独看到图像;我想避免这种情况 可以选择按钮上的文本。我也想避免这种情况。

我试着做in button[disabled]。但有些效果是无法消除的。就像 上图:1 px;位置:相对;和图像。


当前回答

input[type="button"]:disabled,
input[type="submit"]:disabled,
input[type="reset"]:disabled,
{
  //  apply css here what u like it will definitely work...
}

其他回答

如果你将你的style (.css)文件更改为SASS (.scss),请使用:

button {
  background-color: #007700;
  &:disabled {
    background-color: #cccccc;
  }
}

当你的按钮被禁用时,它会直接设置不透明度。首先,我们要设置它的不透明度为

.v-button{
    opacity:1;    
}

为禁用按钮应用灰色按钮CSS。

button[disabled]:active, button[disabled],
input[type="button"][disabled]:active,
input[type="button"][disabled],
input[type="submit"][disabled]:active,
input[type="submit"][disabled] ,
button[disabled]:hover,
input[type="button"][disabled]:hover,
input[type="submit"][disabled]:hover
{
  border: 2px outset ButtonFace;
  color: GrayText;
  cursor: inherit;
  background-color: #ddd;
  background: #ddd;
}

CSS:

.disable{
   cursor: not-allowed;
   pointer-events: none;
}

你可以在那个按钮上添加任何装饰。 要更改状态,可以使用jquery

$("#id").toggleClass('disable');

对于我们所有使用bootstrap的人来说,你可以通过添加"disabled"类并使用以下方法来改变样式:

HTML

<button type="button"class="btn disabled">Text</button>

CSS

.btn:disabled,
.btn.disabled{
  color:#fff;
  border-color: #a0a0a0;
  background-color: #a0a0a0;
}
.btn:disabled:hover,
.btn:disabled:focus,
.btn.disabled:hover,
.btn.disabled:focus {
  color:#fff;
  border-color: #a0a0a0;
  background-color: #a0a0a0;
}

请记住,添加“disabled”类并不一定禁用按钮,例如在提交表单中。禁用它的行为使用disabled属性:

<button type="button"class="btn disabled" disabled="disabled">Text</button>

一个工作提琴与一些例子可在这里。