How to draw a box on hover with CSS

joellehelm

Joelle

Posted on January 3, 2020

How to draw a box on hover with CSS

Hey everyone, I recently learned how to draw a box on hover using CSS and thought I would make a quick tutorial about it.

First you'll need a word or link to hover over. In the example below I'll be using a class called .navA, here is what the html for this could look like.

<a>Hover</a>
Enter fullscreen mode Exit fullscreen mode

Next you'll want to open a css file that is connected to either your html file or your component if you're using react. We will use transition to draw the box over time. I want to draw my box starting from the bottom and go left to right. So first i'll write out transition and give it a border-bottom and then I can set how long it will take for that part of the border to show up. Repeat this step for each side of the border.

.navA {
  text-decoration: none;
  transition: border-bottom .2s, border-left .4s, border-top .6s, border-right .9s;

}
Enter fullscreen mode Exit fullscreen mode

Cool now you know how to draw a box on hover with CSS. Play around with it and try changing the colors.

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
joellehelm
Joelle

Posted on January 3, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About