A loading spinner in CSS 3 using image sprite

An example of a spinner in CSS3 using image sprite, animations and keyframes

The image sprite:

spinner

The code:

<html>
<head>
    <style>
        @-webkit-keyframes spin {
            from {
                background-position: 0px;
            }

            to {
                background-position: -2550px;
            }
        }

        @keyframes spin {
            from {
                background-position: 0px;
            }

            to {
                background-position: -2550px;
            }
        }

        .spinner-container-outer {
            position: fixed;
            z-index: 175;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            text-align: center;
            width: 100%;
            height: 100%;
        }
        .spinner-container-outer:before {
            content: '';
            display: inline-block;
            height: 100%;
            vertical-align: middle;
        }

        .spinner-container-inner {
            display: inline-block;
            vertical-align: middle;
        }

        .spinner {
            height: 85px;
            width: 85px;
            background-image: url("spinner.png");
            -webkit-animation: spin 1s infinite;
            animation: spin 1s infinite;
            -webkit-animation-timing-function: steps(30);
            animation-timing-function: steps(30);
        }
    </style>

</head>

<body>

    <div class="spinner-container-outer">
        <div class="spinner-container-inner">
            <div class="spinner"></div>
        </div>
    </div>

</body>
</html>

 

Advertisements
Posted in css.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s