The animation fails to function, both when hovering over and when not

    ul {
  display: flex;
  flex-direction: row;
  align-items: center;
  list-style-type: none;
  background-color: $base-gray-t;
  margin: 1em;
  padding: .25em 0 0 0;
  height: 3em;
  border-bottom: 0.375em solid $secondary-color;
  overflow: hidden;
  box-shadow: .05em .05em 1em 0;
}

li {
  position: relative;
  color: $base-gray-light;
  padding: 0.40em;
  font-size: 1.5em;
  font-family: 'Montserrat', sans-serif;
  cursor: pointer;
  z-index: 2;
}

li:not(.active):not(:first-child):before {
  content: '';
  display: block;
  position: absolute;
  bottom: .01em;
  width: 100%;
  height: 2em;
  margin-left: -.4em;
  border-radius: .25em .25em 0 0;
  z-index: -1;
}

li:hover:before {
  background: $primary-color;
  animation: splash .3s ease;
  bottom: .01em
}

@keyframes splash {
  0% {
    bottom: -2em;
    border-radius: 100%;
  }
  100% {
    bottom: .01em;
  }
}

Answer №1

If you want to finish the animation you made for hover, you need to include forwards along with your animation properties like this:

li:hover:before {
  background: $primary-color;
  animation: splash .3s ease forwards;
  bottom: .01em
} 

You can see it in action in this jsfiddle link

Answer №2

Using the transition method is a simpler approach with fewer potential problems. I have made some adjustments to your fiddle to incorporate this method:

https://jsfiddle.net/6t8xLssv/1/

In this version, I have applied the transition to the :before element on hover, with the exception of the active li.

li:before{
  content:'';
  display:inline-block;
  position:absolute;
  bottom:0;
  right:0;
  left:0;
  height:0;
  transition:height 0.2s linear;
  background:pink;
  border-radius:5px 5px 0 0;
  z-index:-1;
}
li:hover:before{
  transition:height 0.2s linear;
  height: 2em;
}
li.active:before{
  display:none;
}

I trust this modification will be beneficial to your project.

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

How to center align an HTML page on an iPhone device

I am currently testing a HTML5 webpage on my iPhone, utilizing CSS3 as well. The page appears centered in all browsers except for the iPhone, where it is left aligned. I have attempted to use the following viewport meta tag: <meta name="viewport" conte ...

Show a directional indicator on hover in the date selection tool

I am currently using a datepicker that looks like this: https://i.sstatic.net/XsrTO.png When I hover over it, three arrows appear to change days or show the calendar. However, I would like to remove these arrows. Here is the code snippet: link: functi ...

List items that are not in any particular order spilling over onto the next

Having an issue with an unordered list where the list items aren't all on the same line. The 5th element is dropping to the next line even though each item is set to 20% of the container. The math adds up, so not sure what's causing the problem. ...

What is causing this element to unexpectedly elongate when I hover on it, despite having a 3D rotation effect applied?

After implementing a rotational hover effect on an element using the following code: transform: perspective(600px) rotateY(-25deg); I encountered a major issue when hovering over it. The element sometimes rotates abruptly and stretches excessively. If y ...

Use CSS height:auto for every element except SVG

Is there a way to scale all images on my site while excluding SVG files using native CSS? .myClass img { height: auto; } I have tried the following, but it only targets SVG files: .myClass img[src$=".svg"] {height: auto;} Using != doesn't seem ...

Issue with scrollable multilevel dropdown menu

Dealing with an extensive menu list, I aimed to restrict them using a scroll. In the demo on CodePen, everything works fine without the scroll. However, upon adding overflow-y:scroll; height:200px;, it leads to an overflow-x issue and hides all the dropd ...

Is there a way to use CSS to make a div expand as much as it can?

I am attempting to accomplish the following; Do you think this is achievable? ...

Is there a way to transition an element from a fixed layout position to an absolute layout position through animation?

I am looking to create a dynamic animation effect for a button within a form. The goal is for the button to move to the center of the form, while simultaneously undergoing a horizontal flip using a scale transform. During the midpoint of this animation, I ...

What is the best way to position this grid container directly beneath the search box using absolute positioning?

<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Unique Starter</title> ...

What could be causing my React Router component to display incorrect styling?

While working with react-router, I encountered an issue where the text from the routed page started appearing in the navbar. Even though I separated it as its own component and it functions correctly, this specific problem persists. As a newcomer to React, ...

What are the steps to turn off the rule .MuiInputBase-inputType-121 in Material UI TextField for email input field because of a display problem?

Here is a snippet of JSX code: import TextField from '@material-ui/core/TextField/TextField'; <Col xs={6}> <TextField pattern=".{3,}" name="fullName" ...

Struggling to align elements in React/JS/M?

My challenge is aligning the elements in the middle of my page. I aim to have 3 elements per row, with n rows depending on the number of "VideoBox" components. It's crucial that these elements fit within the lettering of the P R O F E S S I O N A L ...

Design layout in Angular Material that wraps the content within it

Is there a way to achieve this specific layout with the "plus" icon positioned below the card layout? https://i.sstatic.net/W5ZRM.png I have attempted the code below: <section layout="column" style="background-color: black;"> <md-c ...

Ensuring the input element is correctly aligned in its position

How can I center the input element inside its parent without any top margin? What CSS changes do I need to make? #menu { height:30px; background: #ccc; } #board-name { display:block; margin-left:auto; margin-right:auto; height: 80%; vertical-al ...

Creating a Curved Border with Clip Path in CSS

Hey there! I'm currently attempting to add a speech bubble at the bottom left using clip-path, but I'm struggling to adjust the pixels just right to achieve the clear and exact look I want. Can someone provide suggestions on how to accomplish thi ...

Is there a way to alter the color of radio buttons?

Is there a way to use CSS to change the background color of a radio button? I've searched online, but all the solutions I found involve JavaScript, which I don't fully understand. I attempted this CSS code, but it didn't have the desired eff ...

minimize javascript syntax (stackoverflow 2022)

I'm struggling with this puzzle game. Sometimes, when I start a new game, the pieces get shuffled incorrectly. I tried adding a function to fix it, but it doesn't seem to be working. It's really frustrating and I want to simplify the code as ...

Mastering the art of calculating the width for a responsive scroll menu

I found a useful tutorial on building a scrolling menu for smaller screen sizes. You can check it out here. However, I encountered an issue when trying to add a border width element. Whenever I define the width, it overrides the scrolling: auto; element. ...

Sliding out the sidebar menu with Jquery

Hey there! I'm currently working on implementing a swipe feature for the side menu bar. I have already added a click method in my code, but now I also need to incorporate a swipe technique. When the side bar is opened, I want to remove the inside im ...

Bootstrap dropdown menu fails to expand

I recently attempted to implement a hamburger menu using Bootstrap on my website. After checking and adding the necessary CSS and JS files, I encountered an issue where the menu wasn't expanding as expected. I followed the example code provided on the ...