javascript - 如何更改悬停时的背景图像和文本颜色 CSS MVC 5
问题描述
这是我的div,
<div >
<div class="thumbnail text-center">
<a href="@Url.Action("Index", "Employees")">
<img src="~/AppFiles/Images/Tile.png" class="img-fluid img-thumbnail border border-success">
<div class="caption">
<p>@Resource.Employee</p>
<p>@ViewBag.EmpCount</p>
</div>
</a>
</div>
</div>
当我将鼠标悬停在 div 上时,我想将 的 更改为src
,并且我希望文本的颜色更改为img
'~/AppFiles/Images/HoverTile.png'
class="caption"
white
希望您的建议
解决方案
添加到您的 css 文件中:
.thumbnail:hover {
// Write everything you want to happen after hover
}
“标题”类相同
.caption:hover {
color:white;
}
如果你想用 javascript 做它并更改 src:
<img id="my-img" src="http://dummyimage.com/100x100/000/fff"
onmouseover="hover(this);" onmouseout="unhover(this);" />
function hover(element) {
element.setAttribute('src', 'http://dummyimage.com/100x100/eb00eb/fff');
}
function unhover(element) {
element.setAttribute('src', 'http://dummyimage.com/100x100/000/fff');
}
推荐阅读
- image - 使用 clenquemapimage() 时如何为 opencl 中的图像 2d 对象计算 image_row_pitch?
- c# - Azure Custom Vision Api POST 请求错误,甚至是正确的 ID
- keras - 如何训练 ResNet50?
- typescript - 打字稿转换器 - QuestionToken 丢失
- r - 带有 in_schema 的 tbl 返回“无效的对象名称”错误
- drupal-8 - 如何在 drupal 8 中使用 module_set_weight 函数?
- php - PHP中速记比较的动态计数
- html - 如何创建多行单选按钮html
- reactjs - React Native 如何使用地图在数组中添加对象?
- asp.net-core - 为什么 .NET 5.0.102 的 Context.User.Identity 突然为空?