简体   繁体   English

如何更改鼠标上的图像 hover

[英]How to change image on mouse hover

I am a beginner.我是初学者。 I am working on this webpage salesletter .我正在处理此网页的销售信函 I am trying to change the button color of the add-to-cart buttons by changing their image on mouseover.我试图通过在鼠标悬停时更改它们的图像来更改添加到购物车按钮的按钮颜色。 在此处输入图像描述 I am unable to do so with though with my limited knowledge and google isn't able to help me this time.尽管我的知识有限,但我无法这样做,而谷歌这次无法帮助我。 I'd like to ask for your help on how I am going to be able to do this.我想请您帮助我如何做到这一点。 I tried some codes that I found on google but they dont work.我尝试了一些我在谷歌上找到的代码,但它们不起作用。 I have no knowledge of JS btw.顺便说一句,我不了解 JS。 Thanks!谢谢!

Update: thanks for the help of Jan Kees, I was able to accomplish the goal however, there is a problem.更新:感谢 Jan Kees 的帮助,我能够实现目标,但是有一个问题。 here is my current code:这是我当前的代码:

 .add-2-cart { max-width: 60%; margin-left: auto; margin-right: auto; padding-left: 0%; padding-right: 0%; transition: .5s ease; -webkit-box-shadow: 0px 0px; box-shadow: 0px 0px; }.add-2-cart:hover { transform: scale(1.1); }
 <div class="add-2-cart col-flex-fullwidth"> <a href="https://www.digistore24.com/product/394232" target="_blank"> <img src='images/a2c-1btl-am.png' onmouseover="this.src='images/a2c-1btl-amh.png'" onmouseout="this.src='images/a2c-1btl-am.png'" class="fluid-img"> </a> </div>

Now the problem is the image change does not immediately take effect.现在的问题是图像更改不会立即生效。 I need to hover multiple times on the image before it actually works properly.在它真正正常工作之前,我需要在图像上多次 hover 。

You can do this easily using Javascript您可以使用 Javascript 轻松完成此操作

<img src='LibraryTransparent.png' onmouseover="this.src='picture_mouseo_hover.png';" onmouseout="this.src='picture_no_hover.png';" />

or you can use html only或者您只能使用 html

<img 
    src='normalpic.png' 
    onmouseover="this.src='picture_on_hover.png'"
    onmouseout="this.src='normalpic.png'"
    height="100px"
    width="100px"
>

That's using the adjacent sibling combinator ( + ).那是使用相邻的兄弟组合器( + )。

 .image { height: 100px; }.btn { padding: 10px; background: orange; width: 50px; }.image:hover+.btn { background: red; }
 <img class="image" src="https://www.vectorlogo.zone/logos/stackoverflow/stackoverflow-tile.svg"> <div class="btn">button</div> </img>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM