javascript - 如何仅在悬停而不设置样式时禁用 classList

标签 javascript html css

nxt_question_btn.classList.remove('btns')
.btns{
    margin-top: 10px;
    float: right;
    height: 30px;
    background-color: lightblue;
    border: none;
    outline: none;
    cursor: pointer;
    width: 110px;
}
.btns:hover{
    border: 1px solid black;
    box-shadow: 2px 1px 5px lightblue;
}
        <button id="next" class="btns">Next Question</button>
        <button id="end" class="btns">End Quiz</button>

我想在禁用按钮时禁用悬停选项,我的 Javascript 目前禁用样式和悬停选项。如何仅定位悬停?

最佳答案

使用:not()伪类仅在按钮没有 disabled 属性时应用悬停样式。

.btns{
    margin-top: 10px;
    float: right;
    height: 30px;
    background-color: lightblue;
    border: none;
    outline: none;
    cursor: pointer;
    width: 110px;
}
.btns:not([disabled]):hover{
    border: 1px solid black;
    box-shadow: 2px 1px 5px lightblue;
}
<button id="next" class="btns">Next Question</button>
        <button id="end" class="btns" disabled>End Quiz</button>

或者,you can also use the CSS disabled pseudo class作为选择器。

关于javascript - 如何仅在悬停而不设置样式时禁用 classList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71367233/

相关文章:

javascript - 如何在 Jquery 中编写特定的 ajax 帖子

javascript - 按相关性排序 : How to sort a list to have matching values first?

javascript - 我们可以将文件而不是字符串存储在 Chrome 存储中吗

javascript - 在 Internet Explorer 中向选择添加选项不起作用

javascript - Bootstrap 4 导航栏不折叠

html - 设计第四级菜单项不起作用

javascript - 在SVG中编写<path>数据脚本(读取和修改)

javascript - 从本地存储中的数组打印列表到 DOM

html - 根据两点在Div中绘制颜色

css - 在 Chrome 用户代理样式表中,2px = 0em 是如何实现的?