开发者

How to change a div background image while hover without jQuery?

开发者 https://www.devze.com 2023-02-18 15:38 出处:网络
I want to change the background of a DIV on hover event. Is there a way to do this us开发者_JAVA技巧ing pure CSS?Yeah, this is pretty easy with pure CSS, albeit IE6, if I remember rightly, doesn\'t su

I want to change the background of a DIV on hover event. Is there a way to do this us开发者_JAVA技巧ing pure CSS?


Yeah, this is pretty easy with pure CSS, albeit IE6, if I remember rightly, doesn't support :hover on any elements except for a. But the following should work consistently in other browsers:

div {
    background: #fff url(path/to/image.png) 0 0 no-repeat;
}

div:hover {
    background: #ffa url(path/to/hoverImage.png) 0 0 no-repeat;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消