skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. Reasons to use CSS over JS

    1- CSS is easier than Javascript

    2- JavaScript can be disabled

    3- CSS is faster than JavaScript

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search