Home  >  Article  >  Web Front-end  >  How to achieve revolution around the center of a circle in css3

How to achieve revolution around the center of a circle in css3

藏色散人
藏色散人Original
2023-01-31 10:17:132023browse

css3 Method to realize revolution around the center of a circle: 1. Create an HTML sample file; 2. Define a div; 3. Pass ".out {border-radius: 150px; background-color: sandybrown;... "property to set the outer circle; 4. Use attributes such as animation and transform to define the base point and achieve revolution around the center of the circle.

How to achieve revolution around the center of a circle in css3

The operating environment of this tutorial: Windows 10 system, CSS3 version, DELL G3 computer

How to achieve revolution around the center of a circle in css3 ?

CSS3 animated emoticon package revolves around a circle without rotating

The effect is as shown

How to achieve revolution around the center of a circle in css3

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>公转不自转</title>
  <style>
    /* 外层圆 */
    .out {
      margin-top: 200px;
      margin-left: 200px;
      position: relative;
      height: 300px;
      width: 300px;
      border-radius: 150px;
      background-color: sandybrown;
      box-shadow: 0 0 23px;
    }
    /* 笑脸的容纳框 */
    .cover {
      display: inline-block;
      width: 50px;
      height: 50px;
      position: absolute;
      /* 定义基点 */
      transform-origin: 150px 150px;
      animation: smile linear 5s infinite;
      background-color: springgreen;
    }
    /* 笑脸表情包*/
    img {
      width: 50px;
      height: 50px;
      /*方法1 不自转只需要reverse反向线性就可以了*/
      animation: smile reverse linear 5s infinite;
    }
    @keyframes smile {
      to {
        transform: rotateZ(360deg);
      }
    }
    /* 方法2 */
    /* 默认情况下笑脸会跟随容纳框再5s内旋转360deg,所以只要再变换曲线相同的情况下再让它倒着转360deg就好啦 */
    /* @keyframes no-rotate {
      to {
        transform: rotateZ(-360deg);
      }
    } */
    /* 文本的绝对居中 */
    .out span {
      display: block;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 20px;
    }
  </style>
</head>
<body>
  <div>
    <div>
      <img
        src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1577100031&di=7445f215ef1f860d45fd93be22b52f57&src=http://git.oschina.net/uploads/group/110103951448978.jpg"
        alt="">
    </div>
    <span>和蔼的笑脸</span>
  </div>
</body>
</html>

Recommended study: "css video tutorial

The above is the detailed content of How to achieve revolution around the center of a circle in css3. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn