the stacking order of the ripple effect on a material button

I'm currently working on a material button featuring a captivating ripple effect. The animation for the ripple, known as .circle, appears to be animating on top of its parent element (button) rather than underneath it, causing the text to be obscured. I've double-checked the syntax for using z-index and everything seems correct. Feel free to check out the codepen link for reference: http://codepen.io/theMugician/pen/Bjadpj

button{
  z-index: 2;
  border: 3px solid #222;
  background: transparent;
  overflow: hidden;
  width: 100%;
  outline: none;
  position: relative;

  span{
    z-index: 2;
    font-family: 'Montserrat', sans-serif;
    text-transform: uppercase;
    font-weight: 700;
    font-size: 1.5em;
    color: #222;
    position: relative;
    display: block; 
    user-select: none;
    position: relative;
    overflow: hidden;
    padding: 20px;
    &:hover{cursor: pointer;}
  }
}

.circle{
  z-index: 1;
  display: block; 
  position: absolute;
  background: #5677fc;
  border-radius: 50%;
  transform: scale(0);

  &.animate{
    z-index: 1;
    animation: effect 0.65s linear;}
}

@keyframes effect{
    100%{
    z-index: 1;
    opacity: 1; 
    transform: scale(2.5);
  }
}

Answer №1

By including the circle span within the button span, you are making the circle span a child of the button's span, rendering your z-index settings ineffective. To resolve this issue, simply attach the click event to the button element itself:

$("button").click(function(e){
....

As a result, the button structure should look like this:

<button>
  <span>button</span>
  <span class="circle animate"></span>
</button>

Instead of this nested structure:

<button>
  <span>button
     <span class="circle animate"></span>
  </span>
</button>

Check out the updated Codepen example here: http://codepen.io/anon/pen/mVdBPO

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

Adjust the parent's cross-axis to fit the items

Is it feasible for the parent width to expand in a scenario where the parent implements display: flex; flex-direction: column, and a flex item wider than the parent needs to be accommodated? One important aspect to consider is that the grandparent element ...

Transmitting a Page (View) to an Ajax Function in CodeIgniter

Currently, I am using Codeigniter alongside the Zurb Foundation framework. My objective is to load data into a reveal box (a fancy popup) using AJAX. The challenge here is that I do not want to just load the inner HTML content, but rather the entire HTML i ...

What are some ways to prevent "window.onbeforeunload" from appearing when a form is submitted?

Is there a way to prevent the alert box from appearing when submitting a form using the Submit button below? I want to avoid being prompted to "Leave this page" or "stay on this" after submitting the form. <script> window.onbeforeunload = ...

Is there a way for me to retrieve the submitbuttonnextstatusid value from a generated HTML by targeting the input tag with the id of "submitbutton"?

Can someone help me figure out how to extract the value of submitbuttonnextstatusid from a rendered HTML that contains an input tag with the id "submitbutton"? Here is an example of the HTML I am dealing with and I specifically need to retrieve the value ...

css how to style a table row with a specific identifier

Although this question has been asked millions of times on the internet, my English skills are not great and I struggle to find the right words to search. I have a table with a specific ID set up like this: <table class="tableClass"> <tr id="one ...

How to customize the center text of Chart.js doughnut chart

I've tried every search I can think of, but still can't find a solution to my problem. I want to customize the text in the middle of my doughnut chart (not tooltips). The chart is created using Chart.js and includes a percentage in the center. E ...

Center text inside a circle using CSS styling

Having trouble centering text inside a circular element with the code provided below. I've tried various methods but can't seem to get it aligned both vertically and horizontally. .circle { background: rgba(72, 156, 234, 1); background ...

The Ionic application is experiencing difficulties in loading the JSON file

I am currently delving into the world of Ionic development and utilizing localhost to test my app. My goal is to create a contacts list application where contact details such as name, email, phone number, and avatar are loaded from a JSON file. However, I& ...

Creating a responsive design with dual backgrounds using Tailwind CSS

I have a design in Figma that I want to convert to React using Tailwind CSS while maintaining 100% pixel-perfect accuracy. The design is created for a Macbook Pro 16 inch, which has a width of 1728px. However, I want to center the content within a customiz ...

The CSS file is not appearing, causing the styling not to be applied

I've included the following line in my html file: <link rel="stylesheet" href="css/styles.css"> Despite having the css file linked, the styling is not visible on the page. The HTML remains plain. The structure of my files is as follows: file ...

What is the best way to locate the wrapper element that was generated using the "wrapAll()" method?

Here is a code snippet to consider: (view live example here) $(function() { var wrapper = $("<div class='wrapper'></div>"); $(".a").wrapAll(wrapper); wrapper.css("border", "5px solid black"); // It doesn't seem to work p ...

Activate Bootstrap 4 dropdown on mobile devices/responsive design

In my header, there are some links. As the header shrinks to fit a smaller screen, it switches to mobile view (collapse style). I'd like the dropdown menu to be visible by default, but still allow users to toggle it off and on as needed. In essence, ...

How can jQuery help eliminate white space in HTML code?

Having trouble setting anchor links with dynamic content due to IDs containing spaces. Here's an example: <a href="#shoes">Shoes</a> <a href="#Socks and Sandals"></a> <div class="foot" id="shoes"></div> <div cl ...

Move your cursor over the toggle menu to reveal the concealed image

Is it feasible to have a hidden image (with ID 10) display when hovering over a toggle menu (with ID 9) in Wordpress? The current setup can be seen here: . I would like the ability to hover over the left toggle menu and reveal an image that is currently ...

The CSS3 properties controlling my following element will remain fixed after reaching a specific threshold

After successfully creating my personal portfolio website, I've hit a roadblock when it comes to styling beyond the portfolio grid. Despite my best efforts, progress has been slow and frustrating. Realizing that someone with more expertise could quic ...

Which is better for event handling: one large event or multiple small events?

What is the preferred pattern and rationale behind it? $myElements.delegate(selector, 'event1 event2', function () { if (event.type === 'event1') { /* Handle event 1 */ } if (event.type === 'event2') { /* Handle event 2 ...

Populate dropdown list dynamically in Codeigniter using AJAX and jQuery

Although this question may appear to be a duplicate, none of the other answers provided have solved my issue. My query pertains to populating a dropdown using ajax/jquery. While I can successfully send and receive data in JSON format, it doesn't seem ...

What is the best method to retrieve the value of a DIV id and submit it to a form using PHP and jQuery

Greetings! I am looking to extract the value of a div and pass it into a PHP form using POST method. Below is the code snippet for the dynamic change in the div id = "caption": <div id="caption">Alumina Jade Metallic</div> UPDATE This code ...

Tips on incorporating additional spacing between columns in Bootstrap 4

Is there a way to increase the distance between these two columns? <div class="row "> <div class="col-md-6 shadow"> ... </div> <div class="col-md-6 shadow "> ... </div> </div> ...

I am encountering a problem while performing JavaScript validations

In jQuery or using the element's ID, I can validate a textbox. For example: var field = document.getElementById('tbxSearchField').value if (field == "") {alert("please enter text");} The HTML code is as follows: <input class="input" id ...