How to change the opacity of image on hover using css

坚强是说给别人听的谎言 提交于 2019-12-18 19:44:44

问题


I'm trying to figure out how to set all images to be 50% opacity initially, and then change to 100% opacity on hover.

I tried setting this rule in the .css file but it gives a parse error:

img {
  opacity:0.4;
  filter:alpha(opacity=40); 
}
img:hover {
  opacity:1.0;
  filter:alpha(opacity=100); 
}

回答1:


Your code is good- verified in this Fiddle with a friendly fish: http://jsfiddle.net/Qrufy/

<img src="http://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Colossoma_macropomum_01.jpg/800px-Colossoma_macropomum_01.jpg" />

img {
    opacity: 0.5;
    filter: alpha(opacity=40);
}

img:hover {
    opacity: 1.0;
    filter: alpha(opacity=100);
}

The opacity property works in all modern browsers, and the filter:alpha covers <= IE8.



来源:https://stackoverflow.com/questions/18223663/how-to-change-the-opacity-of-image-on-hover-using-css

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