如果元素有类,是否可以在CSS中禁用悬停事件?

Ahm*_*aud 4 html javascript css html5 css3

如果元素有类,是否可以在CSS中禁用悬停事件

Tur*_*nip 8

你可以使用:not()选择器:

.myElement {
    display: inline-block;
    padding: 10px;
    border-radius: 4px;
    background: #CADE75;
    text-decoration: none;
    color: #6D6D6D;
}

/* important bit */
.myElement:not(.dontHover):hover {
    background: #b5d335;
}
Run Code Online (Sandbox Code Playgroud)
<a href="#" class="myElement">An element that hovers</a>
<a href="#" class="myElement dontHover">An element that doesn't</a>
Run Code Online (Sandbox Code Playgroud)