Jump to content

Img hover css

stefanmz
Go to solution Solved by bowrilla,

Well, it depends on what you want to do.

 

First, there's the css filter property, which offers stuff like saturation, greyscale, contrast, etc and they are animatable. IE doesn't work though and might clash with the old proprietary IE filter property. You'll apply those filters overall and the only option I could think of in order to partially apply it would be to display the same image multile times stacked ontop and using the css mask property. That's pretty messy though.

 

The next option would be to not use the image within an <img> (old school and outdated) or <picture> (the modern way to go) tag but to apply it as a background image. That way you can simply switch out the image on :hover. However that is not animatable so it will be a hard transition.

 

Another option for a switch between images that is animatable is stacking the two images and setting opacity on :hover to 0. That can be easily animated.

 

With React (and other frameworks) you could also switch out the image when the cursor is on top of the object.

 

Pick your poison.

Hey just wondering can I cerate a hover element in css like image:hover that can also change the color of an image?

 

Link to comment
Share on other sites

Link to post
Share on other sites

How do you envision the color of the image changing?

For example, if a box element with a certain color overlaid over the image is enough, you can use something like shown here in this example from w3schools: https://www.w3schools.com/css/tryit.asp?filename=trycss_css_image_overlay_fade

 

Everything in .overlay decides the color and such of the box, while .container:hover .overlay decides the opacity of that box.

In general I think this is the sort of page of information you're looking for: https://www.w3schools.com/css/css3_images.asp

Including it showing options such as making the image grayscale.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Well, it depends on what you want to do.

 

First, there's the css filter property, which offers stuff like saturation, greyscale, contrast, etc and they are animatable. IE doesn't work though and might clash with the old proprietary IE filter property. You'll apply those filters overall and the only option I could think of in order to partially apply it would be to display the same image multile times stacked ontop and using the css mask property. That's pretty messy though.

 

The next option would be to not use the image within an <img> (old school and outdated) or <picture> (the modern way to go) tag but to apply it as a background image. That way you can simply switch out the image on :hover. However that is not animatable so it will be a hard transition.

 

Another option for a switch between images that is animatable is stacking the two images and setting opacity on :hover to 0. That can be easily animated.

 

With React (and other frameworks) you could also switch out the image when the cursor is on top of the object.

 

Pick your poison.

Use the quote function when answering! Mark people directly if you want an answer from them!

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, bowrilla said:

Well, it depends on what you want to do.

 

First, there's the css filter property, which offers stuff like saturation, greyscale, contrast, etc and they are animatable. IE doesn't work though and might clash with the old proprietary IE filter property. You'll apply those filters overall and the only option I could think of in order to partially apply it would be to display the same image multile times stacked ontop and using the css mask property. That's pretty messy though.

 

The next option would be to not use the image within an <img> (old school and outdated) or <picture> (the modern way to go) tag but to apply it as a background image. That way you can simply switch out the image on :hover. However that is not animatable so it will be a hard transition.

 

Another option for a switch between images that is animatable is stacking the two images and setting opacity on :hover to 0. That can be easily animated.

 

With React (and other frameworks) you could also switch out the image when the cursor is on top of the object.

 

Pick your poison.

well I chose the third option ,with the hover and opacity. Thanks! That was a very helpful and resourceful answer

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×