HTML and CSS are used to create a Button Hover Effect. Before Selector and Border Radius property is used to create this button hover effect.
Table of Contents
Creating HTML Button
First of all, we will create a new HTML file and create a button using the button tag inside the body.
Body CSS
Then we will create a CSS file and do some styling. First of all I have done styling of main body of our page, using body selector.
body
{
padding:0;
margin: 15% auto;
text-align:center;
background-color:#e2b808;
}
Button CSS
Then we will write some CSS code for our Button. Its background would be set to none, the position would be relative and y-overflow would be hidden. Transition value is set to one second to make the transition smooth.
button
{
padding:30px 40px;
border:1px solid #910c00;
background:none;
position:relative;
font-weight:bold;
font-size:20px;
color:#910c00;
transition:1s;
overflow-y:hidden;
cursor:pointer;
}
Before Selector CSS
Then we will create another Button using before selector. The content of this button would be empty. Position would be set to absolute which means its position would be with respect to the position of original button whose position value was set to relative. The background color is applied but the width is 100% and height is set to 0px, to hide it. Transition value is set to one second. Z-index is set to -1 to keep it beneath the original button but you will be able to see it once its height is increased, because if you remember we set the background of original button to none.
button::before
{
content:"";
position: absolute;
left:0;
top:0;
width:100%;
height:0px;
transition: 1s;
background-color:#910c00;
z-index:-1;
}
Hover Effect
Then we will apply the hover effect to both button tag and before selector element. The height of before selector is increased to 200% but it wont overflow or exceed the height of original button. Because we set overflow-y to hidden in our original button. Border radius is given to before selector to give the bubble like effect. Color of button is changed so that it wont hide or merge into the background color of before selector.
button:hover::before
{
height:200%;
border-radius: 0 0 75% 75%;
}
button:hover
{
color:#e2b808;
}
CSS Button Hover Effect Video Tutorial
Watch our video tutorial here
Feel free to use this code on your websites and projects. Subscribe to our channel and happy learning.