Yogesh Chauhan's Blog

Filling a button background from left to right using CSS

in CSS on July 30, 2021

This is an example of a simple CSS tricks that could produce a nice animation.

Basically, the trick is into adding a background using linear-gradient and changing its position on hover.

Let’s dive into it.

Let’s create a simple button first.

Add the background using linear-gradient.

Change the size of the background to 200%.

The overall background is doubled now and we can set the position of the background to right. If you want to create animation from right to left, set the background-position to left or change the linear-gradient.

Let’s also change the color of the button for better contarst.

Let’s set the background-position to right on hover.

Still we don’t see the animation. Do we?

At the end, all comes onto the transition property. Let’s add it. You can adjust the speed using the time in the transition property.

That’s it.

Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
File System Integrity: How to Keep an Eye on Your Files and Folder Change?MiscellaneousHow to create a sidebar using pure CSS?CSSWhat are components in Angular?AngularWordPress: How to display slider repeater fields in ACF?WordPressINNER JOIN in PostgresPostgresLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHPHow to add a Pie Chart in Angular App?AngularWhat is IPS(Intrusion Prevention System), How Does It Work and What are the Detection Types?MiscellaneousWhat is Host Hardening and What are some Important Hardening Steps?MiscellaneousWhat are “holes” in a React component?ReactHow to set up the local environment and workspace for Angular development?Angular4 ways to create Date Objects in JavaScriptJavaScript