HTML Academy
Previous task
2D Transforms1/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
Moving objects vertically
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Moving objects horizontally

In this chapter, we will explore the capabilities of 2D transforms in CSS.

What previously could only be done in a browser window using JavaScript (smoothly rearranging and scaling blocks as well as rotating and skewing them) can now easily be implemented in pure CSS.

First, let’s understand the coordinate system in which the object is moved:

The coordinate system in which the object is moved

The key feature to keep in mind is that the Y-axis is directed downward, not upward, since the web page starts at the top-left corner and then flows downward, and CSS uses the inverse coordinate system.

The first movement we make is horizontal. We will move objects left and right.

We use the following syntax to make this and other transforms:

transform: the transform function (transform value)

You can move an object horizontally using the translateX function. The transform function takes a numerical value, and the possible units of measurement are px, %, em, or in.
For example, this function will move the object 100 pixels to the right along the X-axis:

transform: translateX(100px)

By the way, let’s get acquainted! The main character that you will be asked to control and to transform his world using spells is called Pendalf the Blue. You will go on an exciting adventure together with him…

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Moving objects horizontally</title> <meta charset="utf-8"> <link rel="stylesheet" href="world.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="world"> <div class="wizard"></div> <div class="tree"></div> </div> </body> </html>
CSS
.wizard { top: 244px; left: 30px; } .tree { top: 178px; left: 400px; }

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. Add a transform property with the value translateX(250px) to the .wizard block, and move the magician to the right.
    2. And then turn him back by adding another movement property to the transform property:
      transform: translateX(250px) translateX(-250px);.

    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.