Tailwind loader style example

tailwind

Here is an example of a loader styled using Tailwind CSS classes:


<div class="relative w-16 h-16">
    <div
        class="w-full h-full bg-gray-300 rounded-full border-2 border-gray-400 absolute top-0 left-0 flex items-center justify-center">
        <div class="w-6 h-6 bg-gray-400 rounded-full animate-bounce"></div>
    </div>
</div>

In this example, the relative class positions the loader container relatively, the w-16 and h-16 classes set the width and height of the container to 16 pixels, the w-full and h-full classes make the inner element take up the full width and height of the container, the bg-gray-300 class sets the background color to a light gray, the rounded-full class adds rounded corners to the inner element, the border-2 and border-gray-400 classes add a 2 pixel wide gray border to the inner element, the absolute class positions the inner element absolutely within the container, the top-0 and left-0 classes position the inner element at the top left corner of the container, the flex class makes the inner element a flex container, the items-center and justify-center classes center the inner element horizontally and vertically, the w-6 and h-6 classes set the size of the bouncing element

To use the loader, you will need to include the HTML code in your project and apply the appropriate CSS classes to your desired elements.

Here is an example of how you might use the loader in your project:

  1. Add the HTML code for the loader to your project:

<div class="relative w-16 h-16">
    <div
        class="w-full h-full bg-gray-300 rounded-full border-2 border-gray-400 absolute top-0 left-0 flex items-center justify-center">
        <div class="w-6 h-6 bg-gray-400 rounded-full animate-bounce"></div>
    </div>
</div>
  1. Add the CSS classes for the loader to your project’s stylesheet:
.animate-bounce {
    animation: bounce 1s infinite;
}

@keyframes bounce {
    from, 20%, 53%, 80%, to {
        transform: translate3d(0, 0, 0);
    }

    40%, 43% {
        transform: translate3d(0, -30px, 0);
    }

    70% {
        transform: translate3d(0, -15px, 0);
    }

    90% {
        transform: translate3d(0, -4px, 0);
    }
}
  1. Show the loader when needed by adding the visible class to the loader container:

<div class="relative w-16 h-16 visible">
    <div
        class="w-full h-full bg-gray-300 rounded-full border-2 border-gray-400 absolute top-0 left-0 flex items-center justify-center">
        <div class="w-6 h-6 bg-gray-400 rounded-full animate-bounce"></div>
    </div>
</div>