What's the trick to achieving a captivating ripple effect while changing the color of a button?

I'm struggling to achieve the same ripple effect on different background colors for my buttons. Can someone please explain the process to create a white or grey ripple effect that will work seamlessly on any background color? Credit goes to the original creator, you can find their work at https://codepen.io/finnhvman/pen/jLXKJw

/* Button style */
.btn-light {
  border: none;
  border-radius: 2px;
  padding: 12px 18px;
  font-size: 16px;
  text-transform: uppercase;
  cursor: pointer;
  color: black;
  background-color: white;
  box-shadow: 0 0 4px #999;
  outline: none;
}

.btn-dark{
  border: none;
  border-radius: 2px;
  padding: 12px 18px;
  font-size: 16px;
  text-transform: uppercase;
  cursor: pointer;
  color: white;
  background-color: black;
  box-shadow: 0 0 4px #999;
  outline: none;
}

/* Ripple effect */
.ripple {
  background-position: center;
  transition: background 0.8s;
}

.ripple-light:hover {
  background: transparent radial-gradient(circle, transparent 1%, white 1%) center/15000%;
}
.ripple-light:active {
  background-color: grey;
  background-size: 100%;
  transition: background 0s;
}

.ripple-dark:hover {
  background: transparent radial-gradient(circle, transparent 1%, dark 1%) center/15000%;
}
.ripple-dark:active {
  background-color: grey;
  background-size: 100%;
  transition: background 0s;
}
<button class="btn-light ripple ripple-light">Button</button>
<button class="btn-dark ripple ripple-dark">Button</button>

Answer №1

Utilize CSS variables for color customization:

/* Custom Button style */
.btn {
  border: none;
  border-radius: 2px;
  padding: 12px 18px;
  font-size: 16px;
  text-transform: uppercase;
  cursor: pointer;
  color: black;
  background-color: var(--c);
  box-shadow: 0 0 4px #999;
  outline: none;
}
.light {
  --c: #fff;
  color:#000;
}
.dark {
  --c: #000;
  color:#fff;
}
/* Ripple effect */
.ripple {
  background-position: center;
  transition: background 0.8s;
}
.ripple:hover {
  background: var(--c) radial-gradient(circle, #0000 1%, var(--c) 1%) center/15000% ;
}
.ripple:active {
  background-color: grey;
  background-size: 100%;
  transition: background 0s;
}
<button class="btn light ripple">Custom Button</button>
<button class="btn dark ripple">Custom Button</button>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for preventing the unwanted portrayal of a rectangle on canvas?

As a beginner in javascript, I am currently learning about the canvas. I have a question regarding drawing rectangles from right to left and seeing negative numbers in the inputs. Is there a way to display the real size of the rectangle regardless of the d ...

Tips for placing a checkbox above a DIV element when generating checkboxes within a foreach loop

This is the output I have generated This HTML code belongs to me <td class="category" colspan ="2" id="tdcategory1"> <div id="category1" style="border:none !important; overflow:hidden; width:auto; height:auto"> </div& ...

Problem with the transparency of CSS, div, and asp:Image

I am facing an issue with a div that has its opacity set to 60. Within this div, there is an asp:Image element. It seems like the opacity of the div is also affecting the image inside it. I attempted to create a separate class for the image and adjust th ...

How can I modify the font style in Bootstrap?

How can I integrate a custom open font into Bootstrap without using a CDN? Should I create a CSS rule to override Bootstrap's default font or locate the font files in Bootstrap and replace them with my desired font? ...

Cancel your subscription to a PubNub channel when the unload event occurs

Currently, I am developing a multiplayer game in Angular utilizing the PubNub service along with the presence add-on. One of the challenges I am facing is detecting when a player unexpectedly leaves the game. This is crucial for sending notifications to o ...

How can I disable the submit button when there is a change in the form input fields using PHP?

I am looking to disable a button that will submit my form if the fields are not changed. So, if I change a field, I would like to be able to submit the form by enabling the button, but only if at least one field is changed. <?php $listeToitures = $db- ...

Monitoring the property of a variable for changes in Angular 4

I'm interested in monitoring changes to a nested property within a JSON object. I would like to trigger a function whenever this nested property is updated. export class HeaderComponent { user: any; constructor(){ this.user = { option ...

Top method for extracting information from Parse.com Cloud Code (JavaScript SDK)

I have been going through the Parse documentation, but I am feeling a bit lost. I followed a tutorial that recommended using Cloud Code for backend operations. In my user profile Cloud Code, this is what I have: Parse.Cloud.define("getUserInfo", async (re ...

RequireJS - Enabling the loading of multiple module instances

I am working on a custom RequireJS plugin that needs to create a new object instance every time it is called. For illustration purposes, consider the following: define("loader", { load: function(name, req, onload, config) { var instance = GlobalGet ...

Introducing random special characters into currency symbols during the process of exporting data to a CSV file

I'm encountering a strange issue when exporting data to CSV files that contain a currency symbol. An extra junk character is being added to the data alongside the currency symbol. For example, if my data is: France - Admin Fee 1 x £100 The result I& ...

Create a new feature in React JS that allows users to add a component to

I'm having trouble figuring out how to create a function that loads data (from a local json) into a li element, and then adds a new component to the clicked li upon click. Here's an example of what I'm trying to achieve: <ul> < ...

Sharing data between Jasmine JavaScript tests: a complete guide

Currently, I am conducting tests involving reading and writing data (to a server, to a mongo db). While I understand that I should be using mocks for this purpose, I have found a workaround to achieve my goal of writing a document, validating its accuracy ...

JQuery drop-down menu not showing submenus

Currently, I have integrated a Dynamic Drive Script to create a sleek drop-down menu. You can view my website with the implemented menu here. (the menu is represented by the black bar in the middle). Although most functionalities are working smoothly, I ...

The server returned an undefined status code

Seeking guidance in the right direction would be greatly appreciated. I am currently using Node/Express and consider myself a beginner in this area. Attempting to reuse some code from a previous project that was successful, but have encountered roadblocks. ...

Leveraging an HTML file to interact with a Google Spreadsheet via a Textbox input for executing queries with the help of App

I'm working with a spreadsheet that has over 1000 lines, each column representing a field. One of the columns is labeled "Domain," which is the value I need to query. My HTML application needs to have a text box where users can input a domain, and the ...

Making a Jquery Ajax Request in Real Time

Is there a way to make sure that the "Test Data" text is only displayed in the console after the book details are fully loaded into vm.books? I am trying to make a synchronous ajax call for this purpose. The code below is not producing the expected result ...

Can the floated DIVs be prevented from breaking onto a new line if they exceed the container's width?

Take a look at this sample HTML code: <div id="container" style=""> <div id="left" style="float: left; width: 200px;">...</div> <div id="right" style="float: right; width: 100px;">...</div> </div> How can we prevent ...

Customizing material-ui styles within a nested component

I am looking to modify the position of the expandIcon in an ExpansionPanel by changing the right attribute: <ExpansionPanel> <ExpansionPanelSummary expandIcon={<ExpandMoreIcon />}> <Typography className={classes.heading}&g ...

CSS display:inline-block elements are not aligned in the same row

On my website, I have a grid of inline-block divs with a width of 33% each. The goal is to have 3 divs per line. Everything looks good, except for the first line where the first div takes up the entire line and its position is off. You can see it in action ...

Eliminating a mystery space in HTML

I am facing an issue with my website where two pages that are meant to look the same have a different appearance. One of the pages has a blank area at the top, which I would like to remove. I have tried to identify which HTML code is causing this, but so f ...