一、使用方案
css偽類文章來源地址http://www.zghlxwxcb.cn/news/detail-589323.html
- active:元素被點(diǎn)擊時(shí)變色,點(diǎn)擊后顏色消失
- focus:元素被點(diǎn)擊后變色,點(diǎn)擊后顏色不消失
- hover:鼠標(biāo)懸浮時(shí)變色,移除后顏色消失
二、代碼
- template部分代碼
<div v-for="(item, index) of dataForm.subjectList" :key="item.id" class="border-input-border wh-35x mrt-m flex-y-center cursor subject-index" :tabindex="index + 1" @click="clickSubjectIndex(item.index)">
{{ index + 1 }}
</div>
.subject-index:focus,
.subject-index:hover {
background-color: var(--menu-checked);
}
- style部分代碼
.subject-index:focus,
.subject-index:hover {
background-color: var(--menu-checked);
}```
## 三、遇到的問題
由于div等元素?zé)o法接受鍵盤或其他用戶事件,即不支持:focus偽類,可通過增加tabIndex屬性使其支持:focus。
## 四、tabIndex
【全局屬性】 指示其元素是否可以聚焦,以及它是否/在何處參與順序鍵盤導(dǎo)航(通常使用Tab鍵,因此得名)。
文章來源:http://www.zghlxwxcb.cn/news/detail-589323.html
到了這里,關(guān)于純css實(shí)現(xiàn)鼠標(biāo)懸浮、點(diǎn)擊更改元素背景的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!