简体   繁体   English

CSS3悬停无法更改Button图像

[英]CSS3 Hover not working for a Button image to change

I am completely clueless here. 我在这里完全不知所措。 I have hover functions working fine on a nav menu with ul li but now I am trying to hover a single button, and after staring at my code for over 15 minutes, I do not get the clue... 我的鼠标悬停功能在ul li的导航菜单上运行良好,但是现在我试图将鼠标悬停在单个按钮上,并且在盯着我的代码15分钟以上之后,我没有任何头绪...

This is my HTML: 这是我的HTML:

<div>
      <a id="backbutton" href="services.html" title="Go back to Services">Go Back</a>
      <br />
</div>

This is my CSS3: 这是我的CSS3:

#backbutton {
display: block;
width: 200px;
height: 54px;
background: url('../images/BackButton.png') center center no-repeat;
text-indent: -9999px;    
}

This one above is working totally fine. 上面的这个完全正常。 Text is gone and the button displays properly. 文本消失,按钮显示正确。 It's the below code that is not working 这是下面的代码不起作用

#backbutton a:hover {
background: url('../images/BackButtonHover.png') center center no-repeat;
width: 200px;
height: 54px;
}

The image will not replace for my targeted hover image (yes, it is uploaded on my server.) 该图像不会替代我的目标悬停图像(是的,它已上传到我的服务器上。)

Any clues? 有什么线索吗?

#backbutton a:hover

to

#backbutton:hover

 #backbutton { display: block; width: 200px; height: 54px; background: url('http://wiki.openstreetmap.org/w/images/1/1c/OpenClosed.png') center center no-repeat; } #backbutton:hover { background: url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTiC0kOjuPsNSp7qFgKtSZyccyZZtalf58MRnztInW19zW5WV8H1g') center center no-repeat; width: 200px; height: 54px; } 
 <a id="backbutton" href="#" title="Go back to Services">Go Back</a> 

You are trying to assign a :hover property to a link ( a element) that is below the element with id backbutton in the hierarchy. 您试图分配:hover属性的链接( a元素)是与ID的元素下方 backbutton在层次中。

Instead of 代替

#backbutton a:hover

use the selector 使用选择器

#backbutton:hover

and it should work. 它应该工作。 If you want to specify, that it only should affect the link with id backbutton , not any element with that id, use the selector 如果要指定仅影响ID为backbutton的链接,而不影响具有该ID的任何元素,请使用选择器

a#backbutton:hover

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

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