The background-position property does not function properly within keyframes in the Tailwind configuration file

I am currently working on an animation for a gradient background. I have set up the animation and keyframes in my Tailwind configuration file.

These animations are located inside theme->extend. I have verified that they are configured correctly because when I tested the code by adding opacity within the keyframe, it worked as expected. However, when I tried to add the background-position attribute, the animations did not work. My config file looks like the following:

const colors = require("tailwindcss/colors");

module.exports = {
  content: ["./public/**/*.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {
      animation: {
        mainLoading: "mainLoading 1s ease infinite",
      },
      keyframes: {
        mainLoading: {
          "0%": {
            "background-position": "0% 0%",
          },
          "50%": {
            "background-position": "100% 0%",
          },
          "100%": {
            "background-position": "0% 0%",
          },
        },
      },
    },
    colors: {
      transparent: "transparent",
    },
  },
  plugins: [],
  prefix: "tw-",
};

I am using the above animation in the following way in my JavaScript file:

<div className="tw-absolute tw-top-0 tw-left-0 tw-w-full tw-h-full tw-flex tw-flex-col tw-text-center tw-justify-center tw-z-20 tw-bg-gradient-to-r tw-from-white tw-via-gray-300 tw-bg-size-200 tw-animate-mainLoading>

Answer №1

Your customization of theme.colors has completely overridden the default Tailwind palette, causing white and gray-300 to no longer be recognized as colors for the tw-from-white and tw-via-gray-300 classes. It is recommended to set your transparent color in theme.extend.colors.transparent instead.

In addition, the background gradient size matches the element's size, resulting in background-position: 0% 0% and background-position: 100% 0% being essentially the same. Consider setting a different background-size in the x-axis for better visual effect.

const colors = require("tailwindcss/colors");

module.exports = {
  content: ["./public/**/*.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {
      colors: {
        transparent: "transparent",
      },
      animation: {
        mainLoading: "mainLoading 1s ease infinite",
      },
      keyframes: {
        mainLoading: {
          "0%": {
            "background-position": "0% 0%",
          },
          "50%": {
            "background-position": "100% 0%",
          },
          "100%": {
            "background-position": "0% 0%",
          },
        },
      },
    },
  },
  plugins: [],
  prefix: "tw-",
};
<div class="tw-absolute tw-top-0 tw-left-0 tw-w-full tw-h-full tw-flex tw-flex-col tw-text-center tw-justify-center tw-z-20 tw-bg-gradient-to-r tw-from-white tw-via-gray-300 tw-bg-size-200 tw-animate-mainLoading tw-bg-[length:200%_100%]">

Check out this implementation in Tailwind Play.

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

Occasionally, the map may take a moment to fully load

Update: Resolving the issue involved directly calling these two methods on the map object: leafletData.getMap().then(function(map) { map.invalidateSize(); map._onResize(); }); Encountering a minor yet bothersome problem with the Leaflet directive ...

Leveraging multiple css classes within a single class definition

I need some help with this issue, it seems pretty basic but I can't seem to find the solution...sorry for asking a beginner question. Currently, I have multiple HTML elements that share the same CSS classes: <a class="class1 class2 class3">< ...

Exploring the possibilities of customizing gutters in Bootstrap v4 Beta

Is it possible to customize grid gutters at different breakpoints? I am aware that Twitter invested millions of dollars in perfecting Bootstrap v4, and I don't expect to overhaul everything overnight. However, I am curious if there is a way to create ...

Guide on transforming a specified string into a modified regex string using JavaScript

Here are some example strings: 2222 333333 12345 111 123456789 12345678 The expected result is: 2@222 333@333 12@345 111 123@456@789 12@345@678 In other words, the character '@' should be inserted at the 4th, 8th, 12th, etc. position ...

Full-screen modal fade not functioning properly

I am trying to implement multiple fullscreen modals on a single page, but I am facing an issue where they slide in and out at an angle instead of just fading in and out. I have been unable to achieve the desired effect of a simple fade transition. If you ...

Guide to dynamically populating a select dropdown in a Django template with Javascript

Recently, I started learning Django and HTML, but JavaScript is still quite new to me. I'm working on creating a database display page with a filter menu on the side. Here is the code for this particular page: Model.py: class Part(models.Model): ...

Guide on validating an Australian phone number with the HTML pattern

When it comes to PHP, I have found it quite simple to validate Australian phone numbers from input using PHP Regex. Here is the regex pattern I am currently using: /^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ | ...

Having trouble retrieving information in HTML from JSON data

I'm having trouble accessing the API data in my HTML file, which is stored in JSON format in my controller. I've tried various methods but none seem to be working. $scope.examFilterData_College = data[0].colleges; $scope.examFilterData_Course = ...

When the Drawer Component Backdrop is open, users will be blocked from interacting with the page

Is there a way to make the Drawer Component anchored at the bottom still interact with the content above it? I've tried using the persistent and permanent variants, but neither of them worked as they prevented any action when clicking outside the draw ...

Can a unique class name generator be implemented for styled components in MaterialUI?

Currently, I am working on a create-react-app project that uses MaterialUI. In an attempt to switch from JSS to Styled Components, everything is functioning properly but the generated class names are not easily understandable. I came across information su ...

Ways to incorporate lighting into the instancing shader

Is there a way to incorporate ambient and directional lighting into the shader when using InstancedBufferGeometry? For example, I am looking to add lighting effects to a specific instance, like in this example: Below is the vertex shader code: precision ...

Exploring the capabilities of using Watir-webdriver with JavaScript and SignalR polling in Firefox

I am currently dealing with a JavaScript-focused website that utilizes SignalR polling. This has been causing Watir-Webdriver to time out during page loading. I have made some progress by adding the following command: driver.execute_script '$.conne ...

Attempting to develop a kick command for discord using discord.js, which will initiate the kick action based on the user's

I've been trying to implement a discord kick command that specifically targets a user on my server. It may not be the most practical solution, but it's essential for my bot's functionality. Here's the code I have so far: if (command == ...

Is there a method to adjust the order in which components are rendered?

Is there a way to render ComponentOne after ComponentTwo without changing their positions, even though ComponentOne requires several seconds for computation? function HOME(){ //some code return( <> < ComponentOne /> ...

Glitch in the animation of the slideshow

I'm encountering a small bug in the animation of my slideshow on the webpage and I can't seem to locate it. I followed a tutorial for the slideshow from this link: https://www.youtube.com/watch?v=TzAshjkhFQw. However, I only want to display 3 sli ...

Library of CSS styling information

Has anyone come across a reliable javascript library that can retrieve the original style (not computed) of a specific element in the DOM? Essentially, I am looking for something that can provide results similar to what is displayed in Firebug's style ...

Can CSS be used to eliminate shadows from a particular image?

Is it possible to eliminate the shadow from a specific image that is displayed multiple times on various pages of a website? This particular image should not have any shadow. Link to Image The image can be found on pages like this one: Page Link Below ...

The 'length' cannot be searched using the 'in' operator

I am experiencing an issue that I can't quite solve. I have come across solutions for this problem, but they all involve methods that don't use AJAX to retrieve data. If anyone can assist me with this, I would greatly appreciate it. Here is the J ...

Guide on adjusting image dimensions in JTextPane using HTML and CSS in the Java Swing environment

I am looking to add an image (such as a formula created from LaTeX) into JTextPane, using HTML+CSS for text formatting and manually setting its size. I attempted the following approach: import java.awt.Dimension; import javax.swing.JFrame; import javax.swi ...

Resolving Problem of Jumping When 'invalid-feedback' Appeared in Bootstrap 4 Input

There is an input with an add-on and a customized focus that includes a '%' at the end of the field, which is working fine. However, there is a small issue where the error message causes the input to jump when clicked in or out. To see the issue ...