Fun Game: Click the button if you can
Sadat Jubayer
November 23, 2021
• 2 min read
This article will show you how you can build this moving button game with a simple trick!
The output will be like this:
You need to know basics of
- HTML
- CSS
- JavaScript
HTML Sturcture
Just a button! That's all you need on the HTML
CSS
The CSS file contains the basic styles for the Body and the button. And the button is positioned absolutely so that it can be moved by the property Top and Left. Initially, the button is centered with the top 50% and left 50%. To center it perfectly, I have used the transform property, which moves the button itself.
JavaScript - the trick
When the user moves the mouse over the button, the position of the button will be changed. For this, we'll use the top and left the property; this is the trick.
You can change you css sytles using JS, learn more about this
Can you click the button?
Yes, you can click the button; there is a trick! Find it by yourself 😉