4 Simple CSS Hover Transitions for your Elements Background
Tags: webdev, css, html, beginners
Published: 2020-02-06 08:27:55

This video will show you 4 different ways you can perform a CSS background transition on a clickable element. CSS transitions are useful, especially because often mobile and tablet devices no longer have a clickable title or button eg. readme. Instead, the whole element is clickable.
{% youtube OycqzlIsgSM%}

Being able to have nice CSS hover effects allows users on desktop to know the elements are clickable. There are many different ways you can approach this using CSS and transitions. 

We will take a look at:
* Background color changes
* Using transition
* Using special CSS elements like :before
* Applying different transitions effects like:
* Using absolute values to have a top-down transition
* Using border-radius to create a circular transition
* Using border-width to create angled transition

### Background Transition 1
Just changing the background with a smooth transition
<pre>
.v1 {
  transition: 0.25s ease background;
  &:hover {
    background:#e1e1e1;
  }
}
</pre>

### Background Transition 2
Sliding the overlay from the top to the bottom
<pre>
.v2 {
  position: relative;
  overflow: hidden;
  h2,.img,p {
    position: relative;
  }
  &:before {
    content:"";
    display: block;
    position: absolute;
    top:0;
    left:0;right:0;
    bottom:100%;
    background:#e1e1e1;
    transition: 0.25s ease bottom;
  }
  &:hover {
    &:before {
      bottom:0%;
    }
  }
}
</pre>

### Background Transition 3
Creating a circle that expands from the middle
<pre>
.v3 {
    position: relative;
    overflow: hidden;
    h2,.img,p {
        position: relative;
    }
    &:before {
        content:"";
        display: block;
        position: absolute;
        top:50%;
        left:50%;
        border-radius:50%;
        width:0%;
        padding-top:0%;
        transform: translate(-50%,-50%);
        background:#e1e1e1;
        transition: 0.5s ease padding-top, 0.5s ease width;
    }
    &:hover {
        &:before {
            width:150%;
            padding-top:150%;
        }
    }
}
</pre>

### Background Transition 4
Creating an angle that comes from the top right to the bottom left
<pre>
.v4 {
    position: relative;
    overflow: hidden;
    h2,.img,p {
        position: relative;
    }
    &:before {
        content:"";
        display: block;
        position: absolute;
        top:0;
        left:0;
        width:0px;
        height:0px;
        border-style:solid;
        border-width:0px 0px 0 0;
        border-color:#e1e1e1 transparent transparent transparent;
          transition: 0.5s ease border-width;
    }
    &:hover {
        &:before {
            border-width:800px 800px 0 0;
        }
    }
}
</pre>


## Want to see more:
I will try to post new great content every day. Here are the latest items:
* [Designing a Full Website UI using Figma](https://dev.to/adriantwarog/designing-a-full-website-ui-using-figma-48fi)
* [Why you should Whiteboard your Design & Development, UI & UX](https://dev.to/adriantwarog/why-you-should-whiteboard-your-design-development-ui-ux-5g12)
* [How to start using Styled Components for React Native](https://dev.to/adriantwarog/how-to-start-using-styled-components-for-react-native-5don)
* [Creating a Mobile Design and Developing it](https://dev.to/adriantwarog/creating-a-mobile-design-and-developing-it-5c4o)