html - 将鼠标悬停在一个元素上会改变另一个元素吗?

标签 html css button hover

我在按钮中有一个图像。当用户将鼠标悬停在按钮上时,我希望图像反转颜色。我怎样才能做到这一点?

这是我目前的代码:

     <button type="button" onclick="getLocation()" style="margin-right:5px;" class="r26">
     <img class="imgl" src="http://cdn.flaticon.com/png/256/60534.png" style="position: relative;
top:50%; margin-right: 6px; margin-left:-2px;" width="10px">
            <font style="position: relative; top:50%;">Detect Country</font></button>

最佳答案

试试这个:

button:hover > img {
    -webkit-filter: invert(100%);
    filter: invert(100%);
}

JSFiddle Demo

关于html - 将鼠标悬停在一个元素上会改变另一个元素吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30337947/

相关文章:

javascript - ionic View 中缺少标题

html - 在不同的页面大小上隐藏固定宽度的 jquery carousel div 的末端

php - php加载内容后向下滑动页面

html - 水平对齐div中的3个按钮

HTML/CSS - 高度固定的容器中表格单元格的高度不一致

javascript - jsPdf 不适用于 css

html - Div 大小不正确可能是由于填充

javascript - 如何制作气泡图随机位置

java - 我可以向 java JFrame 添加多个按钮吗?

css - 如何在 jQuery Mobile 中将图像用作按钮?