【问题标题】:Sphere revolving around another sphere- CSS球体围绕另一个球体旋转 - CSS
【发布时间】:2018-06-17 16:45:25
【问题描述】:

我正在尝试创建一个球体围绕另一个球体旋转(轨道)的纯 CSS 设计。准确地说,就像月亮绕太阳运行一样。地球的形象恰当地融入了地球的范围。但是月亮的图像不适合月亮的球体。

附上的图片可能有助于更好地理解我的问题

下面是我的 CSS 脚本

    .center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: transparent;
}

        .center .earth {
          position: absolute;
          top: 0;
          width: 200px;
          height: 200px;
          background-image: url(https://www.publicdomainpictures.net/pictures/90000/velka/earth-map.jpg);
          margin: 3em auto;
          border-radius: 50%;
          background-size: 630px;
          animation: spin 30s linear alternate infinite;
          box-shadow: inset 20px 0 80px 6px rgba(0, 0, 0, 1);
          color: #000;``
        }

            .center .earth .moon {
          position: absolute;
          top: calc(50% - 1px);
          left: 50%;
          width: 200px;
          height: 2px;
          transform-origin: left;
          border-radius: 50%;
          /*animation: rotate 10s linear infinite;*/
        }

        .center .earth .moon::before {
          content: url(moon.jpg);
          position: absolute;
          top: -25px;
          right: 0;
          width: 50px;
          height: 50px;
          background: #fff;
          border-radius: 50%;
          /*animation: rotate 10s linear infinite;*/
        }

        @keyframes rotate {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }

        @keyframes spin {
      100% {
        background-position: 100%;
      }
    }

【问题讨论】:

  • 你也可以添加你的html代码
  • 我可以建议你改用SVG 吗? HTML,或就此而言的 CSS,并不是真正为您想要实现的那种行为而设计的,它们是用于传达风格化的超文本(想想报纸或杂志)。
  • @amn 是的,我肯定会研究 SVG。谢谢你的建议。

标签: html css


【解决方案1】:

进行此更改content: "";background-image: url(moon.jpg); 并从类名 .center .earth .moon::before 中删除 background: #fff

body {
  background: black;
}
.center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: transparent;
}

        .center .earth {
          position: absolute;
          top: 0;
          width: 200px;
          height: 200px;
          background-image: url(https://www.publicdomainpictures.net/pictures/90000/velka/earth-map.jpg);
          margin: 3em auto;
          border-radius: 50%;
          background-size: 630px;
          animation: spin 30s linear alternate infinite;
          box-shadow: inset 20px 0 80px 6px rgba(0, 0, 0, 1);
          color: #000;``
        }

            .center .earth .moon {
          position: absolute;
          top: calc(50% - 1px);
          left: 50%;
          width: 200px;
          height: 2px;
          transform-origin: left;
          border-radius: 50%;
          /*animation: rotate 10s linear infinite;*/
        }

        .center .earth .moon::before {
          content: "";
          background-image: url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRsvjrANMGI8aBJSFbsHteVa04rcB1IjjNsbrhm8vTLflfpiG133g);
          position: absolute;
          top: -25px;
          right: 0;
          width: 50px;
          height: 50px;
          border-radius: 50%;
          /*animation: rotate 10s linear infinite;*/
        }

        @keyframes rotate {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }

        @keyframes spin {
      100% {
        background-position: 100%;
      }
    }
<div class="center">
<div class="earth">
<div class="moon">

</div>
</div>
</div>

【讨论】:

猜你喜欢
  • 2014-01-27
  • 2015-04-26
  • 2017-02-21
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多