HTML Academy
On-hover effects: buttons, part 1
2D Transforms23/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 3
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

On-hover effects: buttons, part 2

In this assignment, we will create a second button that has a slightly different effect on the icon: on hover, the icon should increase in size and become completely transparent at the same time, and an additional hidden block with the price .hidden should also be triggered to appear in sync with the latter two actions.

Here we will use a smooth transition between the two opacity values opacity and transform: scale.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>On-hover effects: buttons, part 2</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> <button class="btn-yellow" type="button"> <span class="hidden">25<img src="icons/dollar-6x-white.png" alt="Dollar icon"></span> <img class="icon" src="icons/cart-6x-white.png" alt="Cart icon"> Buy </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; } .hidden { position: absolute; opacity: 0; } .hidden img { width: 24px; height: 24px; margin-left: 5px; vertical-align: top; } .btn-green { background-color: #1abc9c; border-bottom: 2px solid #12ab8d; box-shadow: inset 0 -2px #12ab8d; } .btn-yellow { background-color: #f1c40f; border-bottom: 2px solid #e2b607; box-shadow: inset 0 -2px #e2b607; } .btn-green .icon { width: 24px; height: 24px; transition: all 0.4s ease-in-out; } .btn-green:hover .icon { transform: rotate(360deg) scale(1.2); } .btn-yellow .icon { width: 32px; height: 32px; transition: all 0.4s ease-in-out; } .btn-yellow:hover .hidden { left: 20px; transition: opacity 0.2s ease-in-out; } .btn-yellow:hover .icon { }

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
    1. For .btn-yellow:hover .hidden, set opacity to be equal to 1.
    2. For .btn-yellow:hover .icon set the scale transform to the value 10.
    3. And also set opacity to 0.

    After you complete every change, hover the cursor over the yellow 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.