CSS achieves the effect of rotating the outermost layer of a multi-layer nested structure while keeping other layers unchanged

CSS achieves the effect of rotating the outermost layer of a multi-layer nested structure while keeping other layers unchanged

There is such a scenario: a circular container, the background of the outermost container is an arc. Now the outermost arc needs to be rotated to ensure that the content inside the inner container does not rotate. Next, I will share with you a solution. Let's take a look at the final effect:

Implementation ideas

  • The outermost div is set to have a 50% chamfered border, and the overflow is hidden
  • Set the outermost background to the arc background image
  • Defines outer layer rotation animation, the rotation degree is a positive number
  • Define inner layer rotation animation, the rotation degree is negative
  • Start the animation and start rotating
  • The outer layer rotates with a positive number, and the inner layer rotates with a negative number, which just cancels out the rotation and achieves the ideal effect.

Implementation process

DOM structure part: layout of outer div and inner div

load-panel is the outer div, headPortrait-img-panel is the inner div, loadWhirl is the outer rotation animation, and avatarRotation is the inner rotation animation.

<!--Avatar area-->
<div class="headPortrait-panel">
    <!--Loading layer-->
    <div class="load-panel loadWhirl">
        <!--Avatar display layer-->
        <div class="headPortrait-img-panel avatarRotation">
            <img src="../assets/img/login/[email protected]"/>
        </div>
    </div>
</div>

CSS part: layout the styles and implement the rotation animation logic.

  /*Avatar area*/
  .headPortrait-panel{
    width: 100%;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 50px;

    /*Load layer*/
    .load-panel{
      width: 240px;
      height: 240px;
      border-radius: 50%;
      display: flex;
      justify-content: center;
      align-items: center;
      background: url("../img/login/[email protected]");

      img{
        width: 100%;
        height: 100%;
      }

      // Avatar rotation animation.avatarRotation{
        animation: internalAvatar 3s linear;
        // Animation infinite loop animation-iteration-count:infinite;
      }

      /*Avatar display layer*/
      .headPortrait-img-panel{
        width: 200px;
        height: 200px;
        border-radius: 50%;
        overflow: hidden;
        border: solid 1px #ebeced;

        img{
          width: 100%;
          height: 100%;
        }
      }
    }

    // External rotation animation.loadWhirl{
      animation: externalHalo 3s linear;
      // Animation infinite loop animation-iteration-count:infinite;
    }
  }

  // Define the external halo rotation animation @keyframes externalHalo {
    0%{
      transform: rotate(0deg);
    }
    25%
      transform: rotate(90deg);
    }
    50%{
      transform: rotate(180deg);
    }
    100%{
      transform: rotate(360deg);
    }
  }

  // Define internal avatar rotation animation @keyframes internalAvatar {
    0%{
      transform: rotate(0deg);
    }
    25%
      transform: rotate(-90deg);
    }
    50%{
      transform: rotate(-180deg);
    }
    100%{
      transform: rotate(-360deg);
    }
  }

Project gallery

The above code address: chat-system

After cloning the project locally, visit http://localhost:8020/login to view the effect. The file path for this article is: src/views/login.vue

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  Let you understand the deep copy of js

>>:  The principle and configuration of Nginx load balancing and dynamic and static separation

Recommend

Linux bridge method steps to bridge two VirtualBox virtual networks

This article originated from my complaints about ...

Example of deploying MySQL on Docker

Table of contents 1 What is container cloud? 2 In...

How to configure wordpress with nginx

Before, I had built WordPress myself, but at that...

HTML Learning Notes--Detailed Explanation of HTML Syntax (Must Read)

1. What is HTML markup language? HTML is a markup...

Detailed usage of docker-maven-plugin

Table of contents Docker-Maven-Plugin Maven plugi...

Brief analysis of the introduction and basic usage of Promise

Promise is a new solution for asynchronous progra...

MySQL starts slow SQL and analyzes the causes

Step 1. Enable MySQL slow query Method 1: Modify ...

Complete example of vue polling request solution

Understanding of polling In fact, the focus of po...

Recommended tips for web front-end engineers

Let's first talk about the value of web front...

Detailed explanation of XML syntax

1. Documentation Rules 1. Case sensitive. 2. The a...

The perfect solution to the Chinese garbled characters in mysql6.x under win7

1. Stop the MySQL service in the command line: ne...

Vue implements simple notepad function

This article example shares the specific code of ...

Example of creating circular scrolling progress bar animation using CSS3

theme Today I will teach you how to create a circ...

Detailed explanation of selinux basic configuration tutorial in Linux

selinux ( Security-Enhanced Linux) is a Linux ker...

Hadoop 3.1.1 Fully Distributed Installation Guide under CentOS 6.8 (Recommended)

Foregoing: This document is based on the assumpti...