html - 在悬停/单击时更改图像(颜色)以及链接
问题描述
所以我从昨天开始就一直在使用 Javascript (Vue) 和 html (所以请原谅我的菜鸟),我不知道如何更改“主页”链接描述旁边的图像颜色与链接相同的时间。
我尝试过使用 CSS 类,它可以工作,但只会在您将鼠标悬停在图像上而不是整个链接行上时更改图像颜色。除了 CSS,我还尝试通过“onmouseover”将图像更改为彩色版本,但不知何故立即将图标更改为彩色版本(?)。我猜问题是我通过 a:hover 控制链接颜色,通过单独的类控制图像颜色,所以图像颜色没有连接到链接,但我不知道如何解决这个问题?
非常感谢您!
下面只是侧边栏“主页”部分的片段:
<template>
<div>
<div v-if="currentUser" class="vertical-nav bg-dark" id="sidebar">
<div class="py-1 px-3 mb-4 bg-dark">
</div>
<ul class="nav flex-column bg-dark mb-0">
<li class="nav-item ">
<a href="#" class="nav-link text-white font-bold ">
<div class="document"></div>
<i class="fa mr-3 text-primary fa-fw"></i>
Home
</a>
</li>
</ul>
</div>
</div>
</template>
和 CSS:
/* unvisited link */
a:link {
color: white;
}
/* visited link */
a:visited {
color: white;
}
/* mouse over link */
a:hover {
color: rgb(202, 95, 95) !important;
}
/* selected link */
a:active {
color: rgb(202, 95, 95) !important;
.document {
width: 10px;
height: 12px;
background-size: cover;
background: url("assets/documentWhiteSmall.png") no-repeat;
display: inline-block;
}
.document:hover {
width: 10px;
height: 12px;
background-size: cover;
background: url("assets/otherDocRedSmall.png") no-repeat;
}
解决方案
您可以.document
根据a
css 的悬停来定位您的 div:
a .document {
width: 10px;
height: 12px;
background-size: cover;
background: url("assets/documentWhiteSmall.png") no-repeat;
display: inline-block;
}
a:hover .document {
width: 10px;
height: 12px;
background-size: cover;
background: url("assets/otherDocRedSmall.png") no-repeat;
}
推荐阅读
- centos - yum 更新失败
- c# - 前缀“不能从”重新定义为
在同一个起始元素标签内 - azure - 让 Azure AD SSO 使用两个不同的 URL
- python - 如何将此函数简化为检查列表中所有错误代码的函数?
- r - R-分组和计数?
- android - 如何为 MapBox 设置多个过滤器?
- javascript - 无法理解为什么它给了我:未捕获(承诺)类型错误:无法读取未定义的属性“blabla”
- ruby-on-rails - 使用 Rails API 创建和发送电子邮件附件的最佳实践是什么
- python - Shutil.move 不移动文件夹,而是移动文件夹的内容
- python - 使用字符串和 NaN 提取多索引 pandas 数据帧的最大值