2023-12-10 05:00:01

样式禁用按钮与CSS

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

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

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

我试着:

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

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


当前回答

需要应用css如下所示:

button:disabled,button[disabled]{
    background-color: #cccccc;
    cursor:not-allowed !important;
  }

其他回答

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

.v-button{
    opacity:1;    
}

对于我们所有使用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>

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

考虑以下解决方案

.disable-button{ 
  pointer-events: none; 
  background-color: #edf1f2;
}

CSS:

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

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

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

我认为你应该能够选择一个禁用按钮使用以下:

button[disabled=disabled], button:disabled {
    // your css rules
}