Simple CSS Button Hover Effect using Before Selector

CSS Button Hover Effect

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.

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.

Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Simple Price Range Slider With HTML CSS and JavaScript Circle With Two Colors using CSS Card With Ribbon using HTML and CSS Simple Loading Screen using HTML and CSS Disable Textarea Resizable Property using CSS Button like Links using CSS Simple Dropdown Menu Using HTML and CSS Background Color Transition using CSS Highlight Required Input Fields using CSS Disable HTML Link using CSS Difference Between Descendant Selector and Child Selector How To Change Color and Size of Hr Tag Using CSS How To Center Align HTML Table Convert Checkbox To Toggle Button Using CSS Drawing Stars using HTML and CSS Button Bounce Effect using CSS Image as Text Background using CSS background-clip Property Vertically Rotate HTML Element using CSS Vertical Align Middle using CSS Text Over Image Hover Effect - Css Hover Simple CSS Button Hover Effect using Before Selector