CSS-LESS animation fails to function

I'm currently facing an issue with my script. In the section designated for avatars - images, I am attempting to change the border color upon hovering over the image, however, it doesn't seem to be working as expected.


img {
    margin-right:15px;
    float: left;
    width:68px;
    height: 68px;
    .bdr(40px);
    border:5px solid #eeeeee;
}
img:hover {
    -webkit-animation: avatarAnimation 1s;
    -moz-animation: avatarAnimation 1s;
    -o-animation: avatarAnimation 1s;
    animation: avatarAnimation 1s;
}
@keyframes avatarAnimation {
    25% {
        background: red;
    }
    50% {
        border-color: #f27935;
    }
    75% {
        border-color: #1fbba6;
    }
}

Answer №1

Consider implementing -webkit-keyframes to ensure compatibility with Chrome.

Answer №2

If you are utilizing Less, you have the flexibility to address various platforms by using a mixin:

.create-animations(@name) {
  @keyframes @name {
    // content
  }
  @-webkit-keyframes @name {
    // content
  }
}

Below is an illustration employing another mixin for generating your content (including properties for each step in a variable):

// define the properties for each step
@properties: ~'background: red', ~'border-color:#f27935', ~'border-color:#1fbba6';

// a mixin for creating each step
.create-animation-step(@step, @count) when (@count > 0) {
  .create-animation-step(@step, (@count - 1));
  @pos: @step * (@count);
  @{pos} {top: extract(@properties, @count);}
}

.create-animations(@name) {
  @keyframes @name {
    .create-animation-step(25%, length(@properties));
  }
  @-webkit-keyframes @name {
    .create-animation-step(25%, length(@properties));
  }
}

.create-animations(avatarAnimation);

This will result in the following CSS code being generated:

@keyframes avatarAnimation {
  25% {
    top: background: red;
  }
  50% {
    top: border-color:#f27935;
  }
  75% {
    top: border-color:#1fbba6;
  }
}
@-webkit-keyframes avatarAnimation {
  25% {
    top: background: red;
  }
  50% {
    top: border-color:#f27935;
  }
  75% {
    top: border-color:#1fbba6;
  }
}

Answer №3

Starting from version 2 of Less, it is recommended to use the autoprefix postprocessor plugin for optimal results.

To utilize the autoprefix plugin, your Less code should follow the structure outlined below (save it in a file named file.less):

img {
  margin-right: 15px;
  float: left;
  width: 68px;
  height: 68px;
  border: 5px solid #eeeeee;
  &:hover {
    animation: avatarAnimation 1s;
  }
}

@keyframes avatarAnimation {
  25% {
    background: red;
  }
  50% {
    border-color: #f27935;
  }
  75% {
    border-color: #1fbba6;
  }
}

In the example above, the .bdr(40px); call has been omitted. Afterwards, you can compile the code using lessc --autoprefix file.less, resulting in the following output:

img {
  margin-right: 15px;
  float: left;
  width: 68px;
  height: 68px;
  border: 5px solid #eeeeee;
}
img:hover {
  -webkit-animation: avatarAnimation 1s;
          animation: avatarAnimation 1s;
}
@-webkit-keyframes avatarAnimation {
  25% {
    background: red;
  }
  50% {
    border-color: #f27935;
  }
  75% {
    border-color: #1fbba6;
  }
}
@keyframes avatarAnimation {
  25% {
    background: red;
  }
  50% {
    border-color: #f27935;
  }
  75% {
    border-color: #1fbba6;
  }
}

If desired, you can also specify the target browsers for your project like so:

lessc --autoprefix="> 1%, last 2 versions, Firefox ESR, Opera 12.1" file.less

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

What is the best way to target a specific class to exclude in CSS styling?

Here is the css code snippet: .single-post .container { width: 60%; } not(.single-post) .container{ min-width:92%; } The goal I am aiming for is to have the container width set to 60% on single post pages and 92% on all other pages. T ...

Creating tags in HTML and displaying them on a webpage

I have a code that sends a message from a textarea after completion tags are entered as I wrote. The desired output should be: <h1> Thanks </h1> The expected output is: Transmitter Thanks instead of <h1> Thanks </h1> ...

"Exploring the versatility of Tailwind css: A guide to implementing multiple themes

I know how to customize dark and light themes in tailwind, but I'm curious about extending this functionality to include additional themes such as pink, blue, red, etc. Is there a way to achieve this with regular tailwind CSS? <p className="t ...

Is the dropdown menu fully functional in the latest release of Bootstrap?

For my current website project, I require a dropdown menu within another dropdown menu. However, it seems that the functionality for this feature has been removed in Bootstrap 5.0. Despite trying various methods to create sub-menus, none have been succes ...

What is preventing me from modifying the icon on a dropdown menu?

I've been struggling to change my dropdown icon from the default "carrot" to a Fontawesome one. Despite researching other questions, I still can't find a solution that works for me. <form> <div class="form-group"> <select disab ...

Creating a full-width header in React: A step-by-step guide

I'm facing an issue with the header I created - I want it to be 100% width of the screen, but when I decrease the screen size, it doesn't scale accordingly. Here's my current CSS: <Box style={{ backgroundColor: "RGB(46 ...

Discover the magic of Bootstrap 3.0 Popovers and Tooltips

I'm struggling with implementing the popover and tooltip features in Bootstrap. While I have successfully implemented drop downs and modals, the tooltips are not styled or positioned correctly as shown in the Bootstrap examples, and the popover featur ...

How can I use JavaScript to modify the style of the first unordered list (ul) element without affecting the

function displayMenu(){ var parentElement = document.getElementById("menuItem1"); var lis = parentElement.getElementsByTagName("ul"); for (var i = 0; i < lis.length; i++) { lis[i].setAttribute("style","display: block"); } } When the button is clicke ...

Trouble with margins on tr elements and borders in CSS and HTML

Here are my current findings: http://jsfiddle.net/62hKs/2/ What I desire to achieve: 1) Create a 15px margin between the two red boxes displayed 2) Modify the appearance of the 4 boxes so they resemble only 2, by eliminating the middle red line caused ...

Is the cursor out of bounds?

Can anyone help me identify the cursor that is associated with "forbidden/cancel" actions? I have been searching for it, but I just can't seem to locate it. ...

What is the process for creating a polygon button similar to this one?

I designed a button with a chevron shape similar to the one shown in this Image (Button) link. I have written the code as seen below, but I am facing difficulty creating the blue component on the left side and applying border-radius and box-shadow properti ...

Is there a way to apply a css class to all nested elements in Angular 6 using Ngx Bootstrap?

I've defined a CSS class as follows: .panel-mobile-navs > ul > li { width:100% } Within the HTML, I am utilizing Ngx-bootstrap for a series of tabs like this: <tabset class="panel-mobile-navs" > ... </tabset> My intention is to ...

Ways to create a responsive header image on a website

I recently incorporated a header image on my website using the following code: #header_area { background: url('my_header_image.com'); background-repeat: no-repeat; background-position: top center; } Although my website is responsive ...

Cite an element that has been dynamically loaded

After selecting a menu item, I dynamically add the center section of the webpage using jQuery. The different HTML pages are added in a similar manner, such as: $.get("biosketchStart_Select.html", function (data) { $("#custom_data_container").html(data ...

Stylish Bootstrap sidebar featuring a vibrant background hue

I am facing an issue with my bootstrap layout where I have two columns - one on the LEFT and one on the RIGHT. The left column should be 8 units wide using the Bootstrap's 12 column grid format, while the right column should be 4 units wide as shown b ...

Gradient transition effect changing background color from bottom to top

I am facing an issue where I have a block and I want the background color to animate from bottom to top on hover. Can you please help me identify what is causing this problem? Your assistance is greatly appreciated. .right-block--wrapper { backgroun ...

Customize the appearance of the active head panel in the Bootstrap Accordion

How can I style the active position of the 'panel heading' like this: https://i.sstatic.net/75s2A.jpg I am looking to include a background color and font-weight for the active panel, as well as have the icon positioned downwards... Here is my cu ...

Creating dynamic button animations with Bootstrap 4 without impacting neighboring rows

I'm facing an issue with adding a simple animation to a button in one row of my webpage. When I change the margin-top of the button, all the rows below it also move along with the button. I tried using position-absolute on the button and position-rela ...

Ways to revamp the overall aesthetic of the entire project

Is there a way to change the colors of all elements in a project when a user checks a checkbox, without having to add a class to each element? Perhaps using a service or a different method? ...

Implementing a Responsive Form on an Image Using Bootstrap

I am facing a challenge where I need to position a form on top of a Responsive Image. My goal is to ensure that the form is responsive as well and adjusts its size according to the image. As of now, the image is responsive but I am struggling to make the ...