span:hover不在Firefox中工作但在Chrome

时间:2015-05-18 08:14:27

标签: html css google-chrome firefox hover

我有一段代码,我在Firefox中不起作用。按钮悬停时.icon图像不会改变。它在Chrome中完美运行。



button.add-to-cart-button .button-left .icon {
  display: block;
  position: absolute;
  left: 0;/*RW 6px; */
  top: 0;/*RW  6px; */
  width: 35px;/*RW 21px; */
  height: 31px;/*RW 19px; */
  background: url(http://client4.bostonwebco.com/skin/ideal_responsive/images/custom/add_to_cart.gif) 50% 50% no-repeat;
}
button.add-to-cart-button .button-left {
  display: block;
  text-indent: -5000px;
  overflow: hidden;
  padding-left: 0px !important;/*RW  2px  */
  width: 35px !important;/*RW  30px  */
  position: relative;
  font-size: 11px;
  text-align: center;
  border: 0px;
  height: 31px;
  margin: 0px;
}
button.add-to-cart-button:hover span.button-left:hover span.icon:hover {
  background: url("http://client4.bostonwebco.com/skin/ideal_responsive/images/custom/add_to_cart-over.gif") 50% 50% no-repeat !important;
  display: block;
  border: none;
}

<div class="buttons-row">
  <button class="button main-button add-to-cart-button" type="submit" title="Add to cart">
    <span class="button-right">
      <span class="button-left">
        <span class="lbl" id="lbl_add_to_cart" onmouseover="javascript: lmo(this, event);">Add to cart</span>
        <span class="icon"></span>
      </span>
    </span>
  </button>
</div>
&#13;
&#13;
&#13;

JS小提琴: http://jsfiddle.net/dKcdK/14/

2 个答案:

答案 0 :(得分:5)

您的问题是,如果某个元素的:hover选择器是button的子元素,则它不会响应它。请参阅https://bugzilla.mozilla.org/show_bug.cgi?id=843003

您可以通过将:hover附加到button来简化您的CSS:

button.add-to-cart-button .button-left .icon {
  display: block;
  position: absolute;
  left: 0;/*RW 6px; */
  top: 0;/*RW  6px; */
  width: 35px;/*RW 21px; */
  height: 31px;/*RW 19px; */
  background: url(http://client4.bostonwebco.com/skin/ideal_responsive/images/custom/add_to_cart.gif) 50% 50% no-repeat;
}
button.add-to-cart-button .button-left {
  display: block;
  text-indent: -5000px;
  overflow: hidden;
  padding-left: 0px !important;/*RW  2px  */
  width: 35px !important;/*RW  30px  */
  position: relative;
  font-size: 11px;
  text-align: center;
  border: 0px;
  height: 31px;
  margin: 0px;
}
.add-to-cart-button:hover .icon {
  background: url("http://client4.bostonwebco.com/skin/ideal_responsive/images/custom/add_to_cart-over.gif") 50% 50% no-repeat !important;
  display: block;
  border: none;
}
<div class="buttons-row">
  <button class="button main-button add-to-cart-button" type="submit" title="Add to cart">
    <span class="button-right">
      <span class="button-left">
        <span class="lbl" id="lbl_add_to_cart">Add to cart</span>
        <span class="icon"></span>
      </span>
    </span>
  </button>
</div>

答案 1 :(得分:0)

我有这个解决方案适用于chrome和firefox。为什么不尝试使用FontAwesome而不是将该购物车图标作为图片。您可以看到我的JS Fiddle进行演示。希望这可以帮助。快乐的编码。

CSS:

button{
   width: 100px;
    height: 100px;
    color: #000;
}

button:hover{
    color: red;
}

您也可以将自定义悬停CSS放在button:hover