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.

Social Media Menu with Popup Tooltip using HTML and CSS Horizontal Navigation Menu with HTML and CSS Responsive Sidebar Menu with CSS and JavaScript Cool CSS Button with Hover Animation Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Color Picker Design with HTML CSS and JavaScript 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 Simple Price Range Slider With HTML CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Circle With Two Colors using CSS Simple FAQ Accordion With HTML CSS and JavaScript