CSS: A square-circle loading spinner design

Looking for assistance in creating a spinner using only CSS that resembles the image provided, with only one section of the spinner colored at a time.

In this code snippet, there is a similar spinner but I need to rotate the entire spinner by 22.5° and make modifications to its rays.

Check out the spinner here

HTML:

<div class="spinner"><div>Loading…</div></div>

CSS:

@-webkit-keyframes spin {
    to { transform: rotate(1turn); }
}
@-moz-keyframes spin {
    to { transform: rotate(1turn); }
}
@-ms-keyframes spin {
    to { transform: rotate(1turn); }
}
@keyframes spin {
    to { transform: rotate(1turn); }
}

.spinner {
    position: relative;
    display: inline-block;
    width: 5em;
    height: 5em;
    margin: 0 .5em;
    font-size: 12px;
    text-indent: 999em;
    overflow: hidden;
-webkit-animation: spin 0.8s infinite steps(8);
   -moz-animation: spin 0.8s infinite steps(8);
    -ms-animation: spin 0.8s infinite steps(8);
     -o-animation: spin 0.8s infinite steps(8);
        animation: spin 0.8s infinite steps(8);
        }

.spinner:before,
.spinner:after,
.spinner > div:before,
.spinner > div:after {
    content: '';
    position: absolute;
    top: 0;
    left: 2.25em; /* (container width - part width)/2  */
    width: .5em;
    height: 1.5em;
    border-radius: .2em;
    background: #eee;
    box-shadow: 0 3.5em #eee; /* container height - part height */
    transform-origin: 50% 2.5em; /* container height / 2 */
}

.spinner:before {
    background: blue;
}

.spinner:after {
    transform: rotate(-45deg);
}

.spinner > div:before {
    transform: rotate(-90deg);
}

.spinner > div:after {
    transform: rotate(-135deg);
}

Any help would be greatly appreciated!

Answer №1

Below is a starting point for you with HTML and CSS code:

<--! HTML -->
<div class="wrapper">
    <div class="spinner">
        <div>Loading…
        </div>
    </div>
    <div class="circ"></div>
</div>

/* CSS */
@-webkit-keyframes spin {
    to { transform: rotate(1turn); }
}
@-moz-keyframes spin {
    to { transform: rotate(1turn); }
}
@-ms-keyframes spin {
    to { transform: rotate(1turn); }
}
@keyframes spin {
    to { transform: rotate(1turn); }
}
.wrapper{
    border:1px solid white;
    border-radius:100%;

    position:relative;
    width: 5em;
    height: 5em; 
    border-radius:999px;
    overflow:hidden; 
}
/* Circular mask */
.circ{
    border:1px solid WHITE;
    position:absolute;
    top:10%;
    left:10%;
    right:0;
    bottom:0;
    width:55%;
    height:55%;
    background-color:#fff;
    border-radius:999px;
}
.spinner {
    border:1px solid white; 
    border-radius:100%;/* Round the border */
    position: absolute;
    display: inline-block;
    width: 5em;
    height: 5em;    
    font-size: 12px;
    text-indent: 999em;
    overflow: hidden;
    -webkit-animation: spin 0.8s infinite steps(8);
    -moz-animation: spin 0.8s infinite steps(8);
    -ms-animation: spin 0.8s infinite steps(8);
    -o-animation: spin 0.8s infinite steps(8);
    animation: spin 0.8s infinite steps(8);
}

.spinner:before,
.spinner:after,
.spinner > div:before,
.spinner > div:after {
    content: '';
    position: absolute;
    top: 0;
    left: 1.8em; /* (container width - part width)/2 */
    width: 1.4em; /* longer */
    height: .8em; /* shorter */
    background: #eee;
    box-shadow: 0 4.2em #eee; /* container height - part height */
    transform-origin: 50% 2.5em; /* container height / 2 */
}

.spinner:before {
    background: purple;
}

.spinner:after {
    transform: rotate(-45deg);
}

.spinner > div:before {
    transform: rotate(-90deg);
}

.spinner > div:after {
    transform: rotate(-135deg);
}

The design might remind you of a flower, but feel free to experiment and customize it further.

If you're looking for more spinner options, consider exploring the wide range of free spinners available online. Here's a collection you can check out: http://codepen.io/collection/HtAne/

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

Is there a way to make all Bootstrap column heights equal using only jQuery?

I am currently working on matching the heights of two columns without using an existing library like match-height.js. In this specific case, I have a row with 2 columns where the first column contains a centered black square and the second column contains ...

Merge two methods to create proportional buttons that function flawlessly on Mac Firefox

code I am facing an issue with the buttons in my code. While they work fine on Mac Firefox, they are not proportional. I made modifications to make them proportional as desired, but now they are not working on Mac Firefox. Since I have multiple pages wit ...

The webpage's scrollbar has vanished and the div element is unable to stretch to the bottom

I'm in need of some help understanding why my scrollbar has disappeared and why the scrolling area does not reach the bottom. You can find the website in question here. Appreciate any assistance on this matter. Thanks! ...

Keeping the scroll in place on a Bootstrap4 modal while scrolling through content that is already at the top

On my Bootstrap 4 modal, I have encountered an issue with scrollable content. When I am at the top of the content and try to scroll downwards, nothing happens because I am already at the top. However, if I continue to hold the touch without releasing it, t ...

Achieve the effect of bringing the div and its contents to the top when hovered over, all while keeping

I have designed a popup that includes multiple boxes. I want the width of the box to expand and be visible over all content on the webpage when a user hovers over any ".deviceboxes". I tried using ".deviceboxes:hover" which worked fine for the first box in ...

What steps should I take to create a functional image scrolling effect similar to the one shown in this example?

Recently, I came across and was intrigued by the "image slide effect" featured on their homepage. The way the background image changes as you scroll up, leading you through different introductory slides before reaching the main content of the site caught ...

Issue with row-class functionality in Angular template

Everything seems to be working smoothly with my current template. However, I am facing an issue when trying to separate individual courses (or products) into components, as the row class is not functioning properly and causing the items to stack on top of ...

The content is unclipped with a border-radius and hidden overflow

As I work on incorporating stylistic text inside rounded divs, I encounter a challenge where the text touches the top of the container. While I have successfully managed to customize various content elements such as nested divs and background images, this ...

The TypeScript error reads: "An element is implicitly assigned the 'any' type because an expression of type 'any' cannot be used to index a specific type."

[Hey there!][1] Encountering this TypeScript error message: { "Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ 0: { image: string; title: string; text: string; }; 1: { ...

Issue with triggering function within Material UI Tabs

The issue I encountered cannot be replicated, but I attempted to address it. Within a Material UI element, there is a child element that I inserted - an X icon located in the corner. The parent element is the surrounding box. There are two main problems: ...

The issue with the class attribute being disregarded by Internet Explorer

Having trouble with a complex web page (JavaScript application) where an included style sheet has the following rule: .floatleft { float: left; margin-right: 10px; } There is a DIV element within that layout: <div class="floatleft" width="25%"> ...

Add-on Group for Form Inputs - Is a style element missing? (Bootstrap 4)

I am looking for a way to incorporate a Bootstrap4 input group label between two input fields. While there are "prepend" and "append" styles available, in this scenario, I require a "center" style which seems to be missing. Does anyone have a solution for ...

To prevent the animation from overflowing, set the parent element to have hidden overflow while still displaying the child element

I am facing an issue with two menus that can be toggled using a switch. Each menu item has a dropdown that appears when clicked. The problem arises when switching between the menus, as there is an animation for the transition (slide in and slide out). I wa ...

Choosing Only the Visible Element with CSS

Within my program, there exists a text element that appears in two distinct sections: section A and section B (in the form of a popup). My intention was to create one object using CSS that could be utilized in both areas. By doing so, I would be able to em ...

Clickable regions in Internet Explorer 7 that lack a specific width

Is there a way to make the clickable area of links always stretch to the parents container when the parent container does not have a fixed width? For example, check out this JSFiddle. In Firefox, the link stretches with the text and the li tag, but in IE ...

place a stationary object within a confined space

I have a specific element called #listMDMap that needs to be positioned within the row div. <div class="col-md-6"> <div class="row"> <div id="listMDMap" [style.position]= ...

Allow the width of the container to be determined by the img element

To achieve the desired effect of making the image resolution width dictate the container width without stretching it, I am facing a challenge. Currently, when the text within a paragraph element exceeds the width of the image, the entire container expands. ...

Issue found in Bootstrap-Multiselect plugin: The dropdown menu appears beneath the outer container when overflow-y is applied

My experience with using Bootstrap-Multiselect and encountering an issue where the dropdown disappears when the outer container has overflow-y: scroll and a max-height has prompted me to seek solutions. I am looking for a way to ensure that the dropdown is ...

Resizing cell height in an HTML table is not supported by Angular 5

In my angular application, I've implemented a component that represents a basic HTML table. However, I'm facing an issue with reducing the height of cells within the table. It seems like my CSS styling is not affecting the display as desired. He ...

Sharing CSS styles among multiple single-page applications (SPAs) developed using the React

I am currently working on multiple micro SPAs that exist independently within an Express environment. I am facing a challenge with importing a global CSS file that is located outside of the apps, as it is not being recognized. The use of @import url(asset ...