Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS image transition

Is it really impossible to let CSS recognize the change in src of an image and apply the correct transition, without resulting to the hacks that I find online, such as just placing several images over each other or using a combination of src and background?

It seems like such a deficiency as images are one of any website's main elements (divs, images, text). My question is: is it really not supported directly, and if not, why?

like image 768
Lodewijk Avatar asked Jul 19 '26 04:07

Lodewijk


1 Answers

It is possible. You can create CSS rules to match elements by certain values of certain attributes. This is a very rarely used feature of CSS selectors but it is supported since CSS 2.1 and I've even used it once - works in all browsers, including IE7. You can read more about this here: http://www.w3.org/TR/CSS2/selector.html#attribute-selectors

Example:

img[src='one.png'] { ... }
img[src='two.png'] { ... }

Live demo: http://jsfiddle.net/dJJqf/

like image 71
keaukraine Avatar answered Jul 22 '26 04:07

keaukraine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!