Hover effects are commonly used in web design; for example, a button may adopt a slightly different background color when the cursor hovers over it. Another appealing way to add a hover effect is using very simple CSS animations. It’s just slightly less common and can make your website just slightly more unique. It only takes a minute to implement!
Transform Effects
There are several ways to add simple animations. For example, you could make an object move up slightly. Preview: http://g.recordit.co/bap86WFHek.gif
This can be achieved using just one line of CSS (in this case using class translate-y
):
.translate-y:hover{
transform: translateY(-2px);
}
You can easily adapt this in order to make the object move up:
.translate-y:hover{
transform: translateY(2px);
}
Generally, 2px
is a safe limit. On higher numbers, transformations may start to look glitchy on some browsers.
Shadows
Adding a shadow on hover can also give an interesting touch beyond just changing colors. Preview: http://recordit.co/PwG2mvT1O4
This can be achieved using just one line of CSS (in this case using class boxshadow
):
.boxshadow:hover{
box-shadow: 0 2px 4px rgba(56, 56, 104, 0.17);
}
You can adapt the numbers and colors to get the desired effect. You can experiment with different shadow looks here: jsfiddle.net/nnrt9yaf/.
Transform & Shadow
Personally, I prefer combining both, because it gives a pretty cool effect. Preview: g.recordit.co/GlPv4VTlNH.gif
This can be achieved using the following CSS (in this case using class hoverswagception
):
.hoverswagception:hover{
transform: translateY(-2px);
box-shadow: 0 2px 4px rgba(56, 56, 104, 0.17);
}
Of course, you can also mix & match and add other effects (different text & background colors, etc.). By playing around with these two very simple pieces of CSS, you can create some pretty cool effects. Just don’t overdo it, because you’ll scare your visitors!