gpt4 book ai didi

javascript - 禁用 div 后,将其内容更改为禁用颜色或 css?

转载 作者:行者123 更新时间:2023-11-28 17:48:40 30 4
gpt4 key购买 nike

我在 <div> 中有按钮和图像.当我做 <div>禁用。它的内容不像禁用那样变灰。我仍然可以像启用一样。

如何更改 div 内容背景以禁用颜色(透明)?

<div style="display:inline-block" id="divImgAddOrUpdate" >  
<button id="imgAddOrUpdate" type="submit" class="btn" >
<img src="Images/save.png" alt="" />Add/Update
</button>
</div>

JS

<script type="text/javascript">
$('#divImgAddOrUpdate').prop('disabled', true);
$('#divImgAddOrUpdate *').prop('disabled', true);
</script>

CSS

 .btn {      

border:.1em #868686 solid;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
font-size: 1em;
font-family:Segoe UI;
padding: 5px 10px 5px 5px;
text-decoration:none;
display:inline-block;
text-shadow: 0px 0px 0 rgba(0,0,0,0.3);
text-align:left;
color: #000000;
background-color: #f4f5f5;
background-image: linear-gradient(to bottom, #f4f5f5, #dfdddd);
}
.btn:hover{
border:1px solid #bfc4c4;
background-color: #d9dddd; background-image: linear-gradient(to bottom, #d9dddd, #c6c3c3);
}
.btn img {
vertical-align:middle;
}

JSFiddle

最佳答案

您可以尝试使用 :disabled 伪类和 :not 伪类,如下所示:

/* this is edited from your original style */
.btn:not(:disabled):hover{
border:1px solid #bfc4c4;
background-color: #d9dddd; background-image: linear-gradient(to bottom, #d9dddd, #c6c3c3);
}
/* this is added */
.btn:disabled {
color:grey;
background-color:gray;
}
/* style for graying out the img */
.btn:disabled > img {
filter:gray;
-webkit-filter:grayscale(100%);
-moz-filter:grayscale(100%);
filter:grayscale(100%);
}

这是 working fiddle

关于javascript - 禁用 div 后,将其内容更改为禁用颜色或 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22751729/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com