[css3] 看博客学习别人的旋转的星球_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:20:05
原创
1670人浏览过

定义一个div 太阳轨道sunline,边框显示出来,定义position为relative

#sunline{

  width: 500px;

  height: 500px;

  border:2px solid #000;

立即学习前端免费学习笔记(深入)”;

  border-radius: 50%;

  margin:50px auto;

  position: relative;

  animation:sunRotate 5s;

}

 

定义一个div 太阳sun,把红太阳放在中间,居中显示,定义position为absolute,

距左50%,剧上50%,左边距负的宽度的一半,上边距负的高度的一半

#sun{

  background: red;

  width: 150px;

  height: 150px;

  position: absolute;

  left: 50%;

  top:50%;

  margin-left:-75px;

  margin-top: -75px;

  border-radius: 50%;

}

 

定义一个地球的轨道 earthline,边框显示出来,定义position为absolute,距左50%,剧上负的高度一半,左边距负的宽度的一半

 

#earthline{

  width: 200px;

  height: 200px;

  border:1px solid #000;

  border-radius: 50%;

  position: absolute;

  left: 50%;

  top: -100px;

  margin-left: -100px;

}

 

定义一个div 地球 earth,把地球放在水平居中,太阳轨道垂直地球居中,定义position为absolute,距左50%,剧上50%,左边距负的宽度的一半,上边距负的高度的一半

#earth{

AI大学堂
AI大学堂

科大讯飞打造的AI学习平台

AI大学堂 87
查看详情 AI大学堂

  background: green;

  width: 100px;

  height: 100px;

  border-radius: 50%;

  position: absolute;

  left: 50%;

  margin-left: -50px;

  top: 50%;

  margin-top: -50px;

}

 

定义一个月球moon,定义position为absolute,距左50%,剧上负的高度一半,左边距负的宽度的一半

#moon{

  width: 40px;

  height: 40px;

  background: blue;

  border-radius: 50%;

  position: absolute;

  left: 50%;

  margin-left: -20px;

  top: -20px;

}

 

定义动画@keyframes,100%的进度的时候,旋转一圈

@keyframes sunRotate{

  100%{

    transform:rotate(360deg);

  }

}

 

为太阳轨道sunline绑定动画,使用属性animation,参数:规则名称,执行时间,速度曲线,延迟时间,播放次数,是否反向

animation:sunRotate 10s linear 0s infinite;

 

速度曲线: linear(线性匀速) ease(缓动)

播放次数:infinite(无限次数)

为地球轨道earthline绑定动画

animation:sunRotate 5s linear 0s infinite; 运行时间不一样,这个快

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><style>#sunline{  width: 500px;  height: 500px;  border:2px solid #000;  border-radius: 50%;  margin:100px auto;  position: relative;  animation:sunRotate 10s linear 0s infinite;}#sun{  background: red;  width: 150px;  height: 150px;  position: absolute;  left: 50%;  top:50%;  margin-left:-75px;  margin-top: -75px;  border-radius: 50%;}#earthline{  width: 200px;  height: 200px;  border:1px solid #000;  border-radius: 50%;  position: absolute;  left: 50%;  top: -100px;  margin-left: -100px;  animation:sunRotate 5s linear 0s infinite;}#earth{  background: green;  width: 100px;  height: 100px;  border-radius: 50%;  position: absolute;  left: 50%;  margin-left: -50px;  top: 50%;  margin-top: -50px;}#moon{  width: 40px;  height: 40px;   background: blue;  border-radius: 50%;  position: absolute;  left: 50%;  margin-left: -20px;  top: -20px;}@keyframes sunRotate{  100%{    transform:rotate(360deg);  }}</style></head><body><div id="sunline">  <div id="sun"></div>  <div id="earthline">    <div id="earth"></div>    <div id="moon"></div>  </div></div></body></html>
登录后复制

 

HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号