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

所属分类: 网页制作 / CSS 阅读数: 1146
收藏 0 赞 0 分享

效果就像这样:

不废话,直接上代码!

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.   height
更多精彩内容其他人还在看

Opera中国的WEB标准课程

网页制作Webjx文章简介:在这篇文章里,我要向大家介绍我和其他很多人花费数月时间开发的一个课程——Web标准课程,该课程旨在向大家提供Web设计和开发的坚实基础,无论读者是谁,此教程完全免费、可访问,并且不需要预备知识。当然,我主要还
收藏 0 赞 0 分享

CSS样式表渐进增强的基本概念

网页制作Webjx文章简介:如果你挠着头想弄清楚优雅降级和渐进增强的区别,我告诉你,这是视角问题。优雅降级和渐进增强都考虑网站在各种设备的各种浏览器上如何良好运转。两者区别的关键在于它们各自关注的焦点,以及这种关注对工作流程的影响
收藏 0 赞 0 分享

简单介绍Web Developer插件制作网页

网页制作Webjx文章简介:Firefox浏览器是一个良好支持W3C标准的开放源代码的浏览器,拥有Linux/Windows/Mac版本。因为Firefox浏览器良好支持W3C标准,所以使用Firefox来调试网页是非常好的。 Firefox浏览器是
收藏 0 赞 0 分享

CSS布局带来的巨大影响:CSS display属性值

网页制作Webjx文章简介:网页元素应用上那些与表格相关的display属性值后,能够模仿出与表格相同的特性。我将会在该文中给大家演示这种方法给CSS布局带来的巨大影响。 应原书编辑要求,先在文章顶部给出链接:《Everything You
收藏 0 赞 0 分享

用div css模拟表格对角线

这只是探讨一种CSS模拟表格对角线的用法,实际在工作中可能觉得这样做有点小题大作,这不是本主题讨论的重点。如果对此深以为然的朋友,请一笑过之 首先声明: 这只是探讨一种CSS模拟表格对角线的
收藏 0 赞 0 分享

IE Firefox在css中的差别 (部分)

1、单位问题 问题:任何距离的数值ie可以不加单位,ff必须要求写单位(0除外) 解决:写全单位如padding:0px; 2、水平居中 问题:div里的内容,ie默认为center,而ff默认left 解决:mairgin:0px auto; 3、高度问题
收藏 0 赞 0 分享

不用js可以实现信息提示效果

[code] <style> body { font:verdena; font-size:14px; color:#000 } h1{ font:verdena; font-size:22px; color:#000 } h2{ font:verdena;
收藏 0 赞 0 分享

CSS解决未知高度的垂直水平居中自适应问题

今天有人问起,晚上试着写出来,供参考; 以下代码兼容主流浏览器IE6、IE7、Firefox、Opera。 从最简单的开始………… 一、如何让一个DIV水平居中? 这个简单不作过多说明! [code] <st
收藏 0 赞 0 分享

CSS cursor 属性 -- 鼠标指针样式效果

取值: [ [<uri> ,]* [ auto | crosshair | default | pointer | move | e-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize |
收藏 0 赞 0 分享

css 简单区别ie6,ie7,firefox的写法

同一样式里可以这样 [code] margin:17px; FF +margin:17px; IE6 IE7 _margin:17px; IE6 [/code] 按这个顺序,刚好区分开三个浏览器
收藏 0 赞 0 分享
查看更多