纯CSS3打造属于自己的“小黄人”


Posted in HTML / CSS onMarch 14, 2016

效果就像这样:

纯CSS3打造属于自己的“小黄人”

不废话,直接上代码!

hrml代码:

XML/HTML Code复制内容到剪贴板
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head lang="zh">  
  4.     <meta charset="UTF-8">  
  5.     <title>纯CSS3画出小黄人并实现动画效果</title>  
  6.     <Link href="index.css" type="text/css" rel="stylesheet" />  
  7. </head>  
  8. <body>  
  9.     <!--容器-->  
  10.     <div class="wrapper">  
  11.         <!--小黄人-->  
  12.         <div class="container">  
  13.             <!--头发-->  
  14.             <div class="hairs">  
  15.                 <div class="hairs_one"></div>  
  16.                 <div class="hairs_two"></div>  
  17.             </div>  
  18.             <!--头发-->  
  19.             <!--眼睛-->  
  20.             <div class="eyes">  
  21.                 <div class="eye_left">  
  22.                     <div class="black">  
  23.                         <div class="white"></div>  
  24.                     </div>  
  25.                 </div>  
  26.                 <div class="eye_right">  
  27.                     <div class="black">  
  28.                         <div class="white"></div>  
  29.                     </div>  
  30.                 </div>  
  31.             </div>  
  32.             <!--眼睛-->  
  33.             <!--嘴巴-->  
  34.             <div class="mouth">  
  35.                 <div class="mouth_box"></div>  
  36.             </div>  
  37.             <!--嘴巴-->  
  38.             <!--手-->  
  39.             <div class="hands">  
  40.                 <div class="left_hand"></div>  
  41.                 <div class="right_hand"></div>  
  42.             </div>  
  43.             <!--手-->  
  44.             <!--身体-->  
  45.             <div class="mybody">  
  46.                 <!--裤子-->  
  47.                 <div class="trousers">  
  48.                     <!--裤子突出部分-->  
  49.                     <div class="trousers_top"></div>  
  50.                     <!--裤子口袋-->  
  51.                     <div class="pocket"></div>  
  52.                     <!--三角线-->  
  53.                     <div class="line-left"></div>  
  54.                     <div class="line-right"></div>  
  55.                     <div class="line-bottom"></div>  
  56.                     <!--吊带-->  
  57.                     <div class="condoleBelt">  
  58.                         <div class="left"></div>  
  59.                         <div class="right"></div>  
  60.                     </div>  
  61.                 </div>  
  62.                 <!--裤子-->  
  63.             </div>  
  64.             <!--身体-->  
  65.             <!--脚-->  
  66.             <div class="foot">  
  67.                 <div class="left_foot"></div>  
  68.                 <div class="right_foot"></div>  
  69.             </div>  
  70.             <!--脚-->  
  71.             <!--阴影-->  
  72.             <div class="foot_shadow"></div>  
  73.             <!--阴影-->  
  74.         </div>  
  75.     </div>  
  76. </body>  
  77. </html>    

css代码:

CSS Code复制内容到剪贴板
  1. body {   
  2.   margin: 0;   
  3.   padding: 0;   
  4. }   
  5. .wrapper {   
  6.   width300px;   
  7.   margin100px auto;   
  8. }   
  9. .container {   
  10.   positionrelative;   
  11. }   
  12. .container .mybody {   
  13.   positionabsolute;   
  14.   width240px;   
  15.   height400px;   
  16.   border5px solid #000;   
  17.   border-radius: 115px;   
  18.   background#f9d946;   
  19.   overflowhidden;   
  20.   z-index: 2;   
  21. }   
  22. .container .mybody .trousers {   
  23.   positionabsolute;   
  24.   bottombottom: 0;   
  25.   width: 100%;   
  26.   height100px;   
  27.   border-top6px solid #000;   
  28.   background#2074a0;   
  29. }   
  30. .container .mybody .trousers .trousers_top {   
  31.   width160px;   
  32.   height60px;   
  33.   background#2074a0;   
  34.   positionabsolute;   
  35.   bottombottom100px;   
  36.   left: 0;   
  37.   rightright: 0;   
  38.   margin: 0 auto;   
  39.   border6px solid #000;   
  40.   border-bottomnone;   
  41. }   
  42. .container .mybody .trousers .pocket {   
  43.   width60px;   
  44.   height45px;   
  45.   border6px solid #000;   
  46.   border-radius: 0 0 25px 25px;   
  47.   left: 0;   
  48.   rightright: 0;   
  49.   margin: 0 auto;   
  50.   positionabsolute;   
  51.   bottombottom65px;   
  52. }   
  53. .container .mybody .trousers .line-left,   
  54. .container .mybody .trousers .line-rightright {   
  55.   width30px;   
  56.   height30px;   
  57.   border-bottom-rightright-radius: 100px;   
  58.   border-right6px solid;   
  59.   border-bottom6px solid;   
  60.   positionabsolute;   
  61.   top10px;   
  62. }   
  63. .container .mybody .trousers .line-rightright {   
  64.   rightright: 0;   
  65.   -webkit-transform: rotate(75deg);   
  66.   -moz-transform: rotate(75deg);   
  67.   -o-transform: rotate(75deg);   
  68.   transform: rotate(75deg);   
  69.   -ms-transform: rotate(75deg);   
  70. }   
  71. .container .mybody .trousers .line-bottombottom {   
  72.   height40px;   
  73.   border3px solid #000;   
  74.   left118px;   
  75.   positionabsolute;   
  76.   bottombottom: 0;   
  77.   border-radius: 3px;   
  78. }   
  79. .container .mybody .trousers .condoleBelt {   
  80.   positionabsolute;   
  81. }   
  82. .container .mybody .trousers .condoleBelt .left,   
  83. .container .mybody .trousers .condoleBelt .rightright {   
  84.   width100px;   
  85.   height16px;   
  86.   border5px solid #000;   
  87.   background#2074a0;   
  88.   top: -90px;   
  89.   positionabsolute;   
  90. }   
  91. .container .mybody .trousers .condoleBelt .left:after,   
  92. .container .mybody .trousers .condoleBelt .rightright:after {   
  93.   content'';   
  94.   background#000;   
  95.   width8px;   
  96.   height8px;   
  97.   border-radius: 50%;   
  98.   positionabsolute;   
  99.   top3px;   
  100. }   
  101. .container .mybody .trousers .condoleBelt .left {   
  102.   left: -35px;   
  103.   transform: rotate(45deg);   
  104. }   
  105. .container .mybody .trousers .condoleBelt .left:after {   
  106.   rightright3px;   
  107. }   
  108. .container .mybody .trousers .condoleBelt .rightright {   
  109.   transform: rotate(-45deg);   
  110.   left165px;   
  111. }   
  112. .container .mybody .trousers .condoleBelt .rightright:after {   
  113.   left3px;   
  114. }   
  115. .container .hairs {   
  116.   positionrelative;   
  117. }   
  118. .container .hairs .hairs_one {   
  119.   width130px;   
  120.   height100px;   
  121.   border-top8px solid #000;   
  122.   positionabsolute;   
  123.   transform: rotate(35deg);   
  124.   left24px;   
  125.   top: -17px;   
  126.   border-radius: 50%;   
  127.   animation: hairs 2s ease-in-out infinite;   
  128. }   
  129. .container .hairs .hairs_two {   
  130.   width80px;   
  131.   height80px;   
  132.   border-top6px solid #000;   
  133.   positionabsolute;   
  134.   transform: rotate(15deg);   
  135.   left50px;   
  136.   top: -10px;   
  137.   border-radius: 50%;   
  138. }   
  139. .container .eyes {   
  140.   positionrelative;   
  141.   z-index: 3;   
  142. }   
  143. .container .eyes .eye_left,   
  144. .container .eyes .eye_right {   
  145.   width85px;   
  146.   height85px;   
  147.   border6px solid #000;   
  148.   border-radius: 50%;   
  149.   background#fff;   
  150.   positionabsolute;   
  151.   top60px;   
  152. }   
  153. .container .eyes .eye_left:after,   
  154. .container .eyes .eye_right:after {   
  155.   content'';   
  156.   width28px;   
  157.   height18px;   
  158.   background#000;   
  159.   positionabsolute;   
  160.   top: 40%;   
  161. }   
  162. .container .eyes .eye_left {   
  163.   left27px;   
  164. }   
  165. .container .eyes .eye_left:after {   
  166.   left: -30px;   
  167.   transform: rotate(7deg) skewX(20deg);   
  168. }   
  169. .container .eyes .eye_right {   
  170.   left124px;   
  171. }   
  172. .container .eyes .eye_right:after {   
  173.   rightright: -32px;   
  174.   transform: rotate(-7deg) skewX(-20deg);   
  175. }   
  176. .container .eyes .black {   
  177.   width40px;   
  178.   height40px;   
  179.   background#000;   
  180.   border-radius: 50%;   
  181.   positionabsolute;   
  182.   top24px;   
  183.   left22px;   
  184.   animation: eys_black 5s ease-in-out infinite;   
  185. }   
  186. .container .eyes .white {   
  187.   width20px;   
  188.   height20px;   
  189.   background#fff;   
  190.   border-radius: 50%;   
  191.   positionabsolute;   
  192.   top10px;   
  193.   left10px;   
  194.   animation: eys_white 5s ease-in-out infinite;   
  195. }   
  196. .container .mouth {   
  197.   positionrelative;   
  198.   z-index: 3;   
  199. }   
  200. .container .mouth .mouth_box {   
  201.   positionabsolute;   
  202.   width55px;   
  203.   height35px;   
  204.   border5px solid #000;   
  205.   background#fff;   
  206.   top170px;   
  207.   left90px;   
  208.   border-bottom-left-radius: 30px;   
  209.   transform: rotate(-35deg);   
  210.   animation: mouth_box 5s ease-in-out infinite;   
  211. }   
  212. .container .mouth .mouth_box:after {   
  213.   background#f9d946;   
  214.   width70px;   
  215.   height32px;   
  216.   content'';   
  217.   positionabsolute;   
  218.   border-bottom5px solid #000;   
  219.   transform: rotate(35deg);   
  220.   top: -14px;   
  221.   left6px;   
  222.   animation: mouth_after 5s ease-in-out infinite;   
  223. }   
  224. .container .hands {   
  225.   positionrelative;   
  226.   z-index: 1;   
  227. }   
  228. .container .hands .left_hand,   
  229. .container .hands .right_hand {   
  230.   width80px;   
  231.   height80px;   
  232.   border6px solid #000;   
  233.   transform: rotate(40deg);   
  234.   positionabsolute;   
  235.   background#f9d946;   
  236.   border-radius: 30px;   
  237.   top220px;   
  238.   animation: left_hand 1s ease-in-out infinite;   
  239. }   
  240. .container .hands .left_hand {   
  241.   left: -24px;   
  242. }   
  243. .container .hands .left_hand:after {   
  244.   width6px;   
  245.   border3px solid #000;   
  246.   positionabsolute;   
  247.   content'';   
  248.   transform: rotate(90deg);   
  249.   bottombottom26px;   
  250.   left12px;   
  251. }   
  252. .container .hands .right_hand {   
  253.   rightright26px;   
  254. }   
  255. .container .hands .right_hand:after {   
  256.   width6px;   
  257.   border3px solid #000;   
  258.   positionabsolute;   
  259.   content'';   
  260.   top20px;   
  261.   rightright18px;   
  262. }   
  263. .container .foot {   
  264.   positionrelative;   
  265. }   
  266. .container .foot .left_foot,   
  267. .container .foot .right_foot {   
  268.   width36px;   
  269.   height50px;   
  270.   background#000;   
  271.   positionabsolute;   
  272.   top400px;   
  273. }   
  274. .container .foot .left_foot:after,   
  275. .container .foot .right_foot:after {   
  276.   width60px;   
  277.   height35px;   
  278.   positionabsolute;   
  279.   bottombottom: 0;   
  280.   content'';   
  281.   background#000;   
  282. }   
  283. .container .foot .left_foot {   
  284.   left86px;   
  285.   animation: left_foot 1s ease-in-out infinite;   
  286. }   
  287. .container .foot .left_foot:after {   
  288.   rightright: 0;   
  289.   top20px;   
  290.   border-radius: 30px 0 10px 20px;   
  291. }   
  292. .container .foot .right_foot {   
  293.   left128px;   
  294.   animation: right_foot 1s ease-in-out infinite;   
  295. }   
  296. .container .foot .right_foot:after {   
  297.   left: 0;   
  298.   top20px;   
  299.   border-radius: 0 30px 20px 10px;   
  300. }   
  301. .container .foot_shadow {   
  302.   positionabsolute;   
  303.   top456px;   
  304.   width240px;   
  305.   height2px;   
  306.   background: rgba(0, 0, 0, 0.3);   
  307.   box-shadow: 0 0 2px 4px rgba(0, 0, 0, 0.3);   
  308.   border-radius: 50%;   
  309. }   
  310. @keyframes hairs {   
  311.   30% {   
  312.     transform: rotate(32deg) translate3d(-4px, -2px, 0);   
  313.   }   
  314. }   
  315. @keyframes eys_black {   
  316.   0% {   
  317.     transform: translateX(0px);   
  318.   }   
  319.   20%,   
  320.   40% {   
  321.     transform: translateX(15px);   
  322.   }   
  323.   60%,   
  324.   100% {   
  325.     transform: translateX(0px);   
  326.   }   
  327.   80%,   
  328.   90% {   
  329.     transform: translateX(-15px);   
  330.   }   
  331. }   
  332. @keyframes eys_white {   
  333.   0% {   
  334.     transform: translateX(0px);   
  335.   }   
  336.   20%,   
  337.   40% {   
  338.     transform: translate3d(3px4px0px);   
  339.   }   
  340.   60% {   
  341.     transform: translate(5px5px);   
  342.   }   
  343.   80% {   
  344.     transform: translateX(0px);   
  345.   }   
  346.   100% {   
  347.     transform: translateX(0px);   
  348.   }   
  349. }   
  350. @keyframes mouth_box {   
  351.   40%,   
  352.   43% {   
  353.     width45px;   
  354.     height25px;   
  355.     top175px;   
  356.   }   
  357.   0%,   
  358.   35%,   
  359.   48%,   
  360.   100% {   
  361.     width55px;   
  362.     height35px;   
  363.     top170px;   
  364.     transform: rotate(-35deg);   
  365.   }   
  366. }   
  367. @keyframes mouth_after {   
  368.   40%,   
  369.   43% {   
  370.     width: 60.5px;   
  371.     top: -19.3px;   
  372.     left: 1.5px;   
  373.   }   
  374.   0%,   
  375.   35%,   
  376.   48%,   
  377.   100% {   
  378.     width70px;   
  379.     top: -16px;   
  380.     left3px;   
  381.     transform: rotate(33deg);   
  382.   }   
  383. }   
  384. @keyframes left_hand {   
  385.   0%,   
  386.   50%,   
  387.   100% {   
  388.     transform: rotate(40deg);   
  389.   }   
  390.   30% {   
  391.     transform: rotate(37deg) translateX(1px);   
  392.   }   
  393. }   
  394. @keyframes right_foot {   
  395.   0%,   
  396.   50%,   
  397.   100% {   
  398.     transform: rotate(0deg);   
  399.   }   
  400.   30% {   
  401.     transform: rotate(-8deg);   
  402.   }   
  403. }   
  404. @keyframes left_foot {   
  405.   0%,   
  406.   50%,   
  407.   100% {   
  408.     transform: rotate(0deg);   
  409.   }   
  410.   80% {   
  411.     transform: rotate(8deg);   
  412.   }   
  413. }  

搞定了,没有做浏览器兼容,建议在chrome下浏览,以上就是本文的全部内容,希望对大家的学习有所帮助。

原文:http://www.cnblogs.com/zhangans/p/4883705.html

HTML / CSS 相关文章推荐
CSS3 三维变形实现立体方块特效源码
Dec 15 HTML / CSS
在css3中background-clip属性与background-origin属性的用法介绍
Nov 13 HTML / CSS
css3一款3D字体带阴影效果的实现步骤
Mar 20 HTML / CSS
css3闪亮进度条效果实现思路及代码
Apr 17 HTML / CSS
一款简洁的纯css3代码实现的动画导航
Oct 31 HTML / CSS
css3中单位px,em,rem,vh,vw,vmin,vmax的区别及浏览器支持情况
Dec 06 HTML / CSS
video结合canvas实现视频在线截图功能
Jun 25 HTML / CSS
HTML4和HTML5之间除了相似以外的10个主要不同
Dec 13 HTML / CSS
移动端解决悬浮层(悬浮header、footer)会遮挡住内容的3种方法
Mar 27 HTML / CSS
基于html5 DeviceOrientation 实现微信摇一摇功能
Sep 25 HTML / CSS
canvas画图被放大且模糊的解决方法
Aug 11 HTML / CSS
CSS filter 有什么神奇用途
May 25 HTML / CSS
利用css3-animation实现逐帧动画效果
Mar 10 #HTML / CSS
CSS3对背景图片的裁剪及尺寸和位置的设定方法
Mar 07 #HTML / CSS
用CSS3的box-reflect设置文字倒影效果的方法讲解
Mar 07 #HTML / CSS
CSS3哪些新特性值得称赞
Mar 02 #HTML / CSS
基于DOM+CSS3实现OrgChart组织结构图插件
Mar 02 #HTML / CSS
基于CSS3实现立方体自转效果
Mar 01 #HTML / CSS
CSS3中几个新增加的盒模型属性使用教程
Mar 01 #HTML / CSS
You might like
汉字转化为拼音(php版)
2006/10/09 PHP
php中拷贝构造函数、赋值运算符重载
2012/07/25 PHP
PHP7导出Excel报ERR_EMPTY_RESPONSE解决方法
2019/04/16 PHP
用js控制组织结构图可以任意拖拽到指定位置
2014/01/17 Javascript
JS+CSS实现可以凹陷显示选中单元格的方法
2015/03/02 Javascript
jQuery实现文本展开收缩特效
2015/06/03 Javascript
基于Jquery easyui 选中特定的tab
2015/11/17 Javascript
JavaScript结合Bootstrap仿微信后台多图文界面管理
2016/07/22 Javascript
Select2.js下拉框使用小结
2016/10/24 Javascript
Bootstrap导航简单实现代码
2017/03/06 Javascript
JS异步文件上传(兼容IE8+)
2017/04/02 Javascript
微信小程序 数据遍历的实现
2017/04/05 Javascript
BootStrap 表单控件之单选按钮水平排列
2017/05/23 Javascript
详解React-Native解决键盘遮挡问题(Keyboard遮挡问题)
2017/07/13 Javascript
vue.js的手脚架vue-cli项目搭建的步骤
2017/08/30 Javascript
基于Vue.js 2.0实现百度搜索框效果
2020/12/28 Javascript
实例详解带参数的 npm script
2019/05/28 Javascript
微信小程序实现张图片合成为一张并下载
2019/07/16 Javascript
[03:13]DOTA2-DPC中国联赛1月25日Recap集锦
2021/03/11 DOTA
python单链表实现代码实例
2013/11/21 Python
Python实现的文本简单可逆加密算法示例
2017/05/18 Python
PyQt5实现无边框窗口的标题拖动和窗口缩放
2018/04/19 Python
pandas多级分组实现排序的方法
2018/04/20 Python
Django 开发调试工具 Django-debug-toolbar使用详解
2019/07/23 Python
pandas中的数据去重处理的实现方法
2020/02/10 Python
STAY JAPAN台湾:预订日本民宿
2018/07/22 全球购物
Blancsom美国/加拿大:服装和生活用品供应商
2018/07/27 全球购物
焊接专业毕业生求职信
2013/10/01 职场文书
创新比赛获奖感言
2014/02/13 职场文书
小学老师寄语大全
2014/04/04 职场文书
关于热爱祖国的演讲稿
2014/05/04 职场文书
四风查摆问题自查报告
2014/10/10 职场文书
部门2014年度工作总结
2014/11/12 职场文书
vue基于Teleport实现Modal组件
2021/05/31 Vue.js
Java面试题冲刺第十五天--设计模式
2021/08/07 面试题
关于python爬虫应用urllib库作用分析
2021/09/04 Python