【发布时间】:2016-12-14 20:42:54
【问题描述】:
背景:我不确定发生了什么,但我有一个链接,在 CSS 中与它关联了一个 a:hover。我还有一个图像,当用户滚动相同的文本链接时,它也应该改变颜色。如果用户首先将鼠标悬停在链接文本上,它会改变颜色没有问题。但是一旦他们将鼠标悬停在图像上,它仍然会改变颜色,但鼠标悬停在文本上不再起作用。
问题: 与 onmouseover/onmouseout 关联的 JavaScript 能否抵消 CSS a:hover 效果?
代码如下:
<style type="text/css">
a.cat_cartridge{
text-decoration:none;
color:#e77504;
font:bold 12px arial;
}
a.cat_cartridge:hover {
color:#cd1c1f;
text-decoration:none;
}
</style>
<div class="image-holder" style="width:150px;margin:0px auto;">
<a href="http://dev-store.url.com/product/serta-gel-king-title-/p810093914?pos=1:14&Ntt=Mattresses">
<img onmouseout="document.getElementById('mattresses_link').style.color='#e77504';" onmouseover="document.getElementById('mattresses_link').style.color='#cd1c1f';" src="http://qa-store.url.com/images/marketing/2016/091616-homepage-icon-mattresses.jpg" style="width:150px;height:150px;" />
</a>
</div>
<div class="bottom-copy">
<h3 style="text-align:center;">
<a class="cat_cartridge" href="http://dev-store.url.com/product/serta-gel-king-title-/p810093914?pos=1:14&Ntt=Mattresses" id="mattresses_link">Mattresses</a>
</h3>
</div>
【问题讨论】:
-
为什么要使用脚本悬停?
-
你弄明白了吗?看看我下面的sn-p。
标签: javascript html css