HTML Academy
Custom shadows
2D Transforms22/32
Back to the list of tasks
  • 1. Moving objects horizontally
  • 2. Moving objects vertically
  • 3. Fireball training
  • 4. Increasing and decreasing the size
  • 5. Defending the city
  • 6. The beginning of the journey
  • 7. The maze
  • 8. The battle, part 1
  • 9. The battle, part 2
  • 10. Test: The mysterious card
  • 11. The battle, part 3
  • 12. Test: The shattered crystal
  • 13. The final battle
  • 14. Features of transform-origin, part 1
  • 15. Features of transform-origin, part 2
  • 16. Features of transform-origin, part 3
  • 17. Features of transform-origin, part 4
  • 18. Centering with transform: translate
  • 19. Rotating the text in blocks
  • 20. Rotating the text in the background
  • 21. Custom shadows
  • 22. On-hover effects: buttons, part 1
  • 23. On-hover effects: buttons, part 2
  • 24. On-hover effects: buttons, part 3
  • 25. On-hover effects: the gallery
  • 26. The “stack” of cards
  • 27. Preparing the round menu
  • 28. Round menu, step 1
  • 29. Round menu, step 2
  • 30. Round menu, step 3
  • 31. The round menu, final part
  • 32. Test: Arranging the cards
On-hover effects: buttons, part 2
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

On-hover effects: buttons, part 1

You can achieve quite a few interesting effects using transforms when implementing various interface items, such as a button, for example. You can add some movement to them using transform together with transition, which will create a very simple floating animation.

In the next few examples, we will create effects that are triggered on hover. In all of the cases, we will use the transition property to ensure a smooth transition between the transform and transparency values. We will cover the topic of smooth transitions in detail in upcoming courses.

In this assignment, when we hover over the button, let’s dynamically wrap the icon around its axis and increase its size slightly at the same time.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>On-hover effects: buttons, part 1</title> <meta charset="utf-8"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="buttons"> <button class="btn-green" type="button"> <img class="icon" src="icons/reload-6x-white.png" alt="Reloading the icon"> Refresh </button> </div> </body> </html>
CSS
body { margin: 0; padding: 0; font-family: "Arial Narrow", "Arial", sans-serif; background-color: #f5f5f5; } .buttons { width: 400px; margin: 50px auto; padding: 10px 20px; text-align: center; background-color: white; box-shadow: 0 0 3px #cccccc; } button { position: relative; width: 300px; height: 60px; margin: 20px auto; padding: 0; font-size: 22px; text-align: center; color: white; border: none; outline: none; cursor: pointer; overflow: hidden; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.4s ease-in-out; } button:active { top: 1px; box-shadow: none; } .icon { position: absolute; left: 20px; } .btn-green { background-color: #1abc9c; border-bottom: 2px solid #12ab8d; box-shadow: inset 0 -2px #12ab8d; } .btn-green .icon { width: 24px; height: 24px; transition: all 0.4s ease-in-out; } .btn-green:hover .icon { transform: none; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0

    Add the following to the .btn-green:hover .icon rule:

    1. Perform a 360° clockwise rotation transform.
    2. And scale the transform by assigning it a value of 1.2.

    After you complete every change, hover the cursor over the green button to check your work.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.