Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should I use CSS or Javascript for this hover use case?

I’m building a site where there is an image and icon within a container. I want to be able to hover over the container and the image would move up by 40px, icon would move right by 40px. Do I need to use Javascript in this case or is there a solution that can leverage only CSS?

Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No reason to get JavaScript involved – simply use the pseudo-selector :hover in CSS. Others have suggested various ways to do so in answers to this question.

If you want the image to be animated upwards, not just instantly move, you can use CSS animations as well.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading