CSS Sprites showing broken image icon over image, but hover still works

空扰寡人 提交于 2019-12-22 00:27:30

问题


I can't figure this out..hopefully someone else can.

I have an image button . The hover effect works fine. However, I have the IE broken image icon over the button image.

Lookie here: Funky Image Funky Image Hover

As you can see...they both work except for that annoying broken image.

Here's my CSS:

.donate-btn{
background: transparent url(/custom/img/donate-btn.png) no-repeat;
overflow:hidden;
height:45px;
width:210px;
float:left;
}
.donate-btn:hover{
background: transparent url(/custom/img/donate-btn.png) no-repeat;
height:45px;
width:210px;
background-position: 0 -45px;
}

回答1:


This simply means you are referencing a non-existent image in the source attribute. You should consider using the actual <button> tag instead. It just needs a few extra style attributes to remove borders and padding:

.donate-btn{
    background: transparent url(/custom/img/donate-btn.png) 0 0 no-repeat;
    overflow:hidden;
    height:45px;
    width:210px;
    border: none;
    padding: 0;
    float:left;
}

.donate-btn:hover{
    background-position: 0 -45px;
}

I also simplied your CSS by removing some unnecessary styling in the hover state.

<button class="donate-btn" type="submit"></button>


来源:https://stackoverflow.com/questions/1918820/css-sprites-showing-broken-image-icon-over-image-but-hover-still-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!