【问题标题】:Image Hovers are not working - what is wrong with the code?图像悬停不起作用 - 代码有什么问题?
【发布时间】:2012-12-23 03:32:53
【问题描述】:

似乎我已经尝试了所有我能想到的方法来获取这些图像链接以在悬停时更改图像。现在只显示主要的 navprint.png。我是 html 和 css 的初学者,并且已经为这个问题苦苦挣扎了好几天。这是代码。任何帮助将不胜感激。

html

<li class="navprint"><a href="printcategory.html"><img src="Images/navprint.png"      alt="print button" title="print button"></a></li>

css

.navprint {
    width: 160px;
    height: 30px;
    background-image: url("Images/navprint.png");
}

.navprint:hover {
    background-image: url('Images/navprinthov.jpg');
    width: 160px;
    height: 30px;
}

【问题讨论】:

  • 你的代码工作正常..看到这个FIDDLE
  • 它适用于我的 FF 18。顺便说一句:您可以将 width: 160px;height: 30px; 留在 .navprint:hover 中,因为您已经在 .navprint 中定义了它... :))

标签: html css


【解决方案1】:

试试这个

<li class="navprint">
 <a href="printcategory.html">
   <img src="Images/navprint.png" alt="print button" title="print button" />
 </a>
</li>


.navprint {
    width: 160px;
    height: 30px;
    background-image: url("Images/navprint.png");
}

.navprint:hover {
    background-image: url('Images/navprinthov.jpg');
}

【讨论】:

  • 实际上使PNG透明,然后为悬停添加背景颜色。那行得通。决定不使用翻转图像,因为它太复杂而无法工作。
  • 悬停必须有效,除非图像路径不正确
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-05
  • 2020-10-13
  • 2019-11-06
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
相关资源
最近更新 更多