Activate both animation scaling and endless rotation simultaneously when hovering

I've been experimenting with an animation that involves a link with a scaled background color and continuous rotation effect when hovered. I've attempted to merge the two animations, but unfortunately, it's not working as expected. Below is the code snippet I used. Any suggestions on how to achieve the desired animation?

Desired Outcome:

Upon hovering, I want the after pseudo-element to instantly display with a scaling effect, while simultaneously keeping the border rotating continuously.

body{
 background:black;
 display:flex;
 justify-content:center;
 align-items:center;
 width:100%;
 height:100vh
}
.full-rounded-link {
    position: relative;
    border: 1px solid;
    border-radius: 50%;
    height:60px;
    width:60px;
    display: flex;
    text-align: center;
    align-items: center;
    background: #191F2A;
    border-color: #191F2A;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
    transition: transform 0.3s ease-in-out;
}
.full-rounded-link a {
 color:white
}
.full-rounded-link::before {
    content: "";
    background: red;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 100%;
    transform: scale(0);
    z-index: -1;
    border: 1px dashed #fff;
}
.full-rounded-link:hover::before { 
  animation: spin 10s linear infinite , dance 0.5s ease ;
}
.full-rounded-link:not(:hover)::before {
  animation: scale-down 0.5s ease-in-out forwards;
}

@keyframes scale-down {
  0% {
transform: scale(1);
  }
  100% {
transform: scale(0);
  }
}
@keyframes dance {
  0% {
  transform: scale(0) rotate(360deg);
 }
  100% {
  transform: scale(1) rotate(-360deg);
 }
}
@keyframes spin {
  0% {
   transform: rotate(-360deg);
  }
  100% {
   transform: rotate(360deg);
  }
 }
<div class="full-rounded-link">
        <a  href="/my-link">
          a link
        </a>
      </div>

Answer №1

.cool-link:hover::before {
 transform: scale(1);
 animation: spin 10s linear infinite, bounce 2s linear;
}

@keyframes spin {
 0% {
  transform: rotate(360deg);
 }
 100% {
  transform: rotate(-360deg);
 }
}

@keyframes bounce {
 0% {
  transform: scale(0) rotate(360deg);
 }
 100% {
  transform: scale(1) rotate(-360deg);
 }
}

Answer №2

I tested out this code and it actually worked perfectly. I'm curious as to why you decided to add a comment about the animation not being necessary.

 .full-rounded-link:hover::before,.full-rounded-link:hover:before {
 transform: scale(1) ;
 animation: spin 10s linear infinite;
 }
 
 @keyframes spin { 
  0% {
 -webkit-transform: scale(0) rotate(180deg);
 }
 100% {
 -webkit-transform: scale(1) rotate(-180deg);
 }
 }

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

Changing the color of buttons within the anchor and menu-separator classes in WordPress

https://i.sstatic.net/lYs6O.png Hi everyone, I'm new to WordPress and need help changing a green button to blue. I have found the button in an anchor tag with the class "menu-separator." Is there a way for me to write custom CSS to change its color? ...

Using AJAX to submit data and displaying the results in either an input field or a div

Having a PHP script to track button clicks to a text file <?php if (isset($_POST['clicks1'])) { incrementClickCount1(); } function getClickCount1() { return (int) file_get_contents("count_files/clickcount1.txt"); } function increme ...

Transform HTML strings within JSON inputs into XML elements

Is there a way to properly parse a JSON file using BaseX 10.7 and the json:parse function? The issue I'm facing is that my file contains values with html characters, like the "text" value below: "order": 2, "page_id": 27, "text": "<p>& ...

Getting the string value from a table row using JavaScript

I need to capture the value of result_status from the row labeled status. If all values in the row labeled status are 'pass', then the result_status will also be 'pass'. However, if any one of the values in the row labeled status is &a ...

loading xml data into a table partially using jquery

Currently, I am utilizing AJAX to load and parse XML data. I have constructed a table where I am inserting the data from the XML using a loop. The issue lies in the fact that only around 3000 rows are being inserted into the table even though the XML conta ...

What is the best way to dynamically adjust CSS based on the screen size of the user?

In a typical scenario, as soon as the end user accesses the page, we load all the CSS associated with it. However, the user is usually only concerned with what is visible on the screen initially. This results in unnecessary loading of CSS components for no ...

Hide/Trim the upper right corner of the button

I am looking to customize the top right corner of a button in order to add a badge in that area. Here is an example of what I have in mind: https://i.sstatic.net/j0xdz.png https://i.sstatic.net/uFzDw.png The image on the right showcases my current setup ...

Guide to adding tabs in a dropdown menu using Bootstrap 5

Using bootstrap 5 drop-down menus with tabs inside, I came across a helpful link that shows how to prevent the drop-down menu from closing when clicked inside. How can I incorporate tabs into my menu to achieve a similar layout as shown in this example lat ...

Receiving updates from server without the need for requests (push) in PHP, Apache, MySQL, HTML5

Is there a way in HTML5 to create a push mechanism for ajax requests, such as using WebSockets? I want my logged-in users to receive notifications about new messages without having to constantly send requests to check for updates. Currently, I check for u ...

The stacking order of elements is not affected by the z-index property when using absolute positioning

I have developed a unique custom toggle switch component with the following structure: <template> <div> <label class="switch"> <input type="checkbox" :checked="value" @c ...

Manage and modify data values

Currently, I am developing a weather forecast app and facing an issue with changing the temperature from Celsius to Fahrenheit upon hovering. Despite my attempts, the changes I make either do not reflect or completely erase the line. I am eager to learn ...

Steps for layering three images with distinct red, green, and blue components using HTML and CSS

Is it possible to overlay three versions of an image, each with red, green, and blue components, in order to recreate the original image using only HTML and CSS? I have tried this HTML setup: <div id="container"> <img class="color" id="red" ...

utilizing an ajax request to clear the contents of the div

When I click on Link1 Button, I want to use ajax to empty the contents in the products_list div <button type="w3-button">Link1</button> I need help with creating an ajax call that will clear the products in the product_list when the link1 but ...

Underline Rows in CSS

When designing my website, I decided to organize the content into rows using CSS instead of tables. To create a line separating each row, I used height:px; for each row manually. However, this method resulted in the line jumping around inconsistently acr ...

Tips on how to customize an HTML form submission appearance

Take a look at my file upload form below: <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="filetoupload" id="filetoupload" onchange="this.form.submit();"> </form> I am trying to figure out ...

A particular individual experiencing difficulties executing a script within an HTML form that relies on google.script.run.function()

I've developed an input form that operates within an HTML modal launched from a Google Apps Script in a Google Sheet. This form retrieves values from the sheet, allows users to edit or manipulate them, and then writes the changes back into the sheet u ...

What is the best way to incorporate a dynamic background image into a panel heading using Twitter Bootstrap 3 for a responsive design?

Hey everyone! I'm having trouble adding an image as a background to my panel heading and also including an h3 inside it. Below is the code I am using: <div class="row col-wrap"> <div class="col-lg-4 col"> < ...

Issue observed in Angular Material: mat-input does not show background color when in focus mode

https://i.stack.imgur.com/eSODL.png Looking for a solution regarding the mat-input field <mat-form-field> <input class='formulaInput' matInput [(ngModel)]='mathFormulaInput'> </mat-form-field> The blue backg ...

The element selector is taking precedence over my class selector

Currently tackling a project for my university course and facing an issue with this section of my html+css code: h1, h2, h3 { color: #747d19; } .name_date { color: #861781; } <div class="name_date"> <h3>Shean</h3> &l ...

Enhancing Twitter Bootstrap with custom media queries for an extra-small breakpoint

It came as a surprise to me that Twitter Bootstrap does not include media queries specifically for creating a well-suited version of a website for mobile portrait screens. Defining the width for "mobile portrait" is a bit complicated. In the past, most ph ...