Skip to content

Latest commit

 

History

History

35- hoverable button with animation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
author handle source date likes retweets replies
Ajay Yadav 🎯
@ATechAjay
December 21, 2021 10:48 AM
25
16
1

ATechAjay Ajay Yadav 🎯 (@ATechAjay) - December 21, 2021 10:48 AM

💚Day 3️⃣5️⃣ / 1️⃣ 0️⃣0️⃣ days of Master in CSS Design series!

💥Today we going to design a hoverable button with animation.

❓What's the main logic behind it with the codepen link?

#100DaysOfCode
[#web development](https://twitter.com/hashtag/webdevelopment)
#web

Let me explain!🧵👇 pic.twitter.com/FIV6VWqu9R

📌 This design is made using the "background-position" property.

→ So, first of all, we have to learn what is and how to use the "background-position" property.

↓↓

→ It is used to set the initial position of a background image.

→ If you want to position your background image on the "top" and "left" corner then, you should use these values.

→ background-position: top left;

↓↓ pic.twitter.com/P9Qeen7SSB

3_1473183585112784896

→ There are many values like

  • background-position: top;
  • background-position: top left;
  • background-position: 100% 50%;
  • background-position: top 50%;

→ These values are in percentage.

↓↓ pic.twitter.com/08eEFg9Wgz

3_1473174156493529090

→ Now, how to design a border around the button(using before pseudo-element).

→ This is designed using width and height properties.

→ width of the before pseudo-element = 100% width + 10px extra.

→ height of the before pseudo-element = 100% height + 10px extra.

↓↓ pic.twitter.com/zG2xP7wIUc

3_1473175947012571138

→ The result, after using height and width property.

📌Now we have to center it.

🤔Do you know how to center this before pseudo-element?

→ Answer: left and top property

↓↓ pic.twitter.com/ESsGFGFjRO

3_1473178920941883397

→ For centering it, we have to set half of the extra(10px) values that we defined.

  • but Negative values.

like this!

↓↓ pic.twitter.com/jOcbwBVWM4

3_1473184207824322561

→ The result, after using top and left property.

↓↓ pic.twitter.com/Tmms7UQxQg

3_1473184273918169088

→ Then, we have to set the background size of the pseudo-element with some high values.

→ For animating the background position.

↓↓ pic.twitter.com/6gtSByydS3

3_1473184399764058112

→ Finally, we have to add keyframes.

0 to 50% = bg position (0 0)

50% = bg position (500% 0) at 100% = bg position (0 0)

↓↓ pic.twitter.com/eTgm5maV0O

3_1473184846444785666

→ codepen link:

↓↓ codepen.io/atechajay/pen/…

Thread link