Can a HTML div be created with an animation and a hover-scale effect added to it?

I experimented with using divs as clickable buttons that direct to another page on my website. I added animations to make them rotate into view when the site is loaded. Now, I'm trying to implement a hover effect that will scale the buttons when hovered over. However, it seems like the hover effect is not being recognized properly when the animation is active. Is there a way to combine both the animation and the hover effect successfully?

Thank you for any help or suggestions!

.animation-links div {
  background: #444;
  margin: 10px;
  text-align: center;
  height: 100px;
  transform: rotateY(90deg);
  transform-origin: center;
}
#animation-1 {
  box-sizing: border-box;
  background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
  background-size: 400%;
  animation-name: animated;
  animation-duration: 1s;
  animation-fill-mode: forwards;
  animation-delay: 0.5s;
}

@keyframes animated {
  0% {
    transform: rotateY(90deg);
  }

  100% {
    transform: rotateY(0);
  }
}

.animation-links div:hover {
    transform: scale(1.10);
  }

Answer №1

One reason is due to the use of animation-fill-mode: forwards;.

If the value assigned to animation-fill-mode is not 'none', then the CSS property values will persist after the animation ends.

To address this, I removed animation-fill-mode: forwards; from the #animation-1 style rule and transform: rotateY(90deg); from the .animation-links div style rule. Additionally, I eliminated any extra { characters and styles placed outside of braces.

Take a look at the snippet below:

.animation-links div {
  background: #444;
  margin: 10px;
  text-align: center;
  height: 100px;
  transform-origin: center;
}
#animation-1 {
  box-sizing: border-box;
  background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
  background-size: 400%;
  animation-name: animated;
  animation-duration: 1s;
  /*animation-fill-mode: forwards;*/
  animation-delay: 0.5s;
  transition: transform 1s ease;
}


@keyframes animated {
  0% {
    transform: rotateY(90deg);
  }

  100% {
    transform: rotateY(0);
  }
}

.animation-links div:hover {
    transform: scale(2);
  }
<div class="animation-links">
  <div id="animation-1">Animation 1</div>
</div>

You can try it out yourself here.

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

Using JQuery to Enhance the Highlight Effect: Tips and Tricks

Exploring the functionality of the "highlight" JQuery effect: http://docs.jquery.com/UI/Effects/Highlight You have the ability to modify the background color of any DIV element with a fade in/out effect. However, the provided example demonstrates trigge ...

Clicking on AngularJS ng-click to navigate to a different page within an Ionic framework application

My goal is to navigate to another page when clicking on a button in the Ionic navbar at the top. However, I am encountering an issue where upon clicking, all nav bar buttons disappear. Interestingly, using dummy codes triggers an alert successfully. But w ...

How can you correctly include a link to a plain text sitemap file in an HTML document?

Could this code effectively inform Google to index my sitemap (or acknowledge its presence)? <link rel="sitemap" href="./sitemap.txt" type="text/plain" title="Sitemap" /> Google's guidelines allow plain t ...

Can anyone shed some light on why the CSS code is not functioning properly within my HTML file?

My CSS doesn't seem to be working in my HTML. I have linked it correctly, but it's not displaying properly - even showing empty in the CSS tab of Chrome Inspector. The links are there, so I'm not sure why it's not functioning correctly. ...

It's impossible to center text in Bootstrap 5

Creating a website for my school project has been challenging, especially when it comes to centering text. I have been struggling to position the text in the middle of the background picture despite trying various methods. Here is the HTML code: pastebin ...

The Unique Font That Mysteriously Blocks Fake Italic Styles on Webkit Browsers

Currently, I am utilizing the PT Sans Narrow font in my project, which unfortunately only offers regular and bold styles. As a result, I require the browser to apply faux italics when needed. Strangely, this functionality is only working on non-webkit brow ...

The enigmatic borders of a website

While working on a custom Wordpress theme, I encountered an issue where the entire body of the page was slightly pushed down. Using Chrome's inspector tool, I identified the following problematic styles: <style type="text/css" media="screen> ...

Using CSS Grid to Create Three Rows of Equal Height

I am facing an issue with my vertical menu that stretches 100% height. The rows inside this menu need to have equal height and be stretched to fit the container. Additionally, I noticed that adding a button seems to drop the container slightly below the pa ...

Guide on adding a button to a mat-table in Angular

I am looking to add a delete button or an Angular trash icon to a mat-table in an Angular application. Can anyone guide me on how to achieve this? Here is my current table code: <mat-table #table [dataSource]="ELEMENT_DATA"> <ng-container cdk ...

The validation process is still failing even though the correct credentials have been entered

I'm diving into the world of Javascript and DOM today, but I've hit a roadblock. Can you take a look at this code snippet and help me figure out what's causing me to always end up in the else block, no matter what I input in the text field? ...

Guide on incorporating JSON information into an HTML table

Currently, I am retrieving data that needs to be added to an HTML table once it is received. I have attempted some methods, but I am unable to dynamically add the data after the page has loaded. I aim to accomplish this using either JavaScript or jQuery. ...

What is the significance of "HandleValidSubmit()" consistently being executed in Blazor?

After reviewing my code, I noticed that the button functionality is not behaving as expected. Specifically, regardless of whether I click the Delete or Submit button, it always triggers HandleValidSubmit() and executes UpdateQuizAsync. This causes an issue ...

Maintaining the current tabIndex while navigating between NextJS pages involves setting the tabIndex state in each

What is the best way to store and retrieve the current tabIndex when moving from one page to another? (One idea is to create a function that saves the current index in the sessionStorage and then retrieves it when the page loads) For example: ...

Numerous volume sliders catering to individual audio players

I'm currently working on implementing volume sliders for multiple audio players, similar to what you can find on . With the help of Deepak, I've managed to create code that allows me to control play/pause and adjust the volume of various audio pl ...

Show a compact graphic in the upper-right-hand corner

Hey, I have this interesting idea but CSS isn't my strong suit. Any thoughts on how to achieve it? I'm looking to create a new class that, when applied to an item (like a div), displays a small clickable pre-defined image in the Top-Right corne ...

When elements are arranged side by side without using floats, the alignment at the top is not correct

I am having trouble aligning multiple divs next to each other using inline-flex. They are not lining up properly on top (refer to the screenshot). Interestingly, if I remove the svg, the divs align correctly. ...

Ways to ensure that the dropdown content remains visible even after the mouse has exited the trigger element

There are three buttons arranged in a row, and when one is hovered over, dropdown content appears underneath all three buttons. However, the content disappears when the mouse moves down to it. Unfortunately, images cannot be posted inside yet** https://i.s ...

Instructions on submitting a form containing multiple select lists using the enter key

After researching various threads, I have come across solutions using the JS onkeypress function to trigger actions with input fields. However, in my case, I need to implement this functionality with a form that consists of multiple select lists instead of ...

Is it possible to modify a scss style in Prestashop?

I have encountered an issue while using a default theme in Prestashop 1.6 that I need assistance with. My goal is to move the navbar up by 25px. I understand that I should make changes to #block_top_menu { padding-top: 25px; } in blocktopmenu.scss, which ...

Can anyone provide guidance on how to create this particular shadow effect using CSS?

Is there a method to use CSS to create a green shadow in that particular shape? ...