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

CSS positioning layout (position, positioning layout skills)

1. What is positioning? The position attribute in...

JavaScript to achieve mouse tailing effect

Mouse effects require the use of setTimeout to ge...

An article teaches you how to use Vue's watch listener

Table of contents Listener watch Format Set up th...

Implementation of the login page of Vue actual combat record

Table of contents 1. Preliminary preparation 1.1 ...

Implementation steps for Docker deployment of SpringBoot applications

Table of contents Preface Dockerfile What is a Do...

Create a virtual environment using venv in python3 in Ubuntu

1. Virtual environment follows the project, creat...

Cross-domain issues in front-end and back-end separation of Vue+SpringBoot

In the front-end and back-end separation developm...

MySQL database migration quickly exports and imports large amounts of data

Database migration is a problem we often encounte...

Solutions to MySql crash and service failure to start

I have been in contact with PHP for so long, but ...

Detailed explanation of CocosCreator project structure mechanism

Table of contents 1. Project folder structure 1. ...

HTML form submission method case study

To summarize the form submission method: 1. Use t...

Example of how to mosaic an image using js

This article mainly introduces an example of how ...

Solution to the ineffectiveness of flex layout width in css3

Two-column layout is often used in projects. Ther...

Zabbix monitoring solution - the latest official version 4.4 [recommended]

Zabbix 2019/10/12 Chenxin refer to https://www.za...

Detailed examples of Docker-compose networks

Today I experimented with the network settings un...