CSS画出一个可爱神奇的多啦A梦

天成岩寺寺入山崖石做瓦,佛观殿外嶂连崖。碧空崖上水滴泄,胜似阳春雨打葩。

小叮当简单颜色单一,操作起来也很容易上手。接下来的一个实例就是用css画出一个多啦A梦,首先将其分为头部,和身体。然后,再根据身体各部分细节进行进一步的具体刻画。

由于最近一直在学习JavaWeb方面的东西,所以,我的这个小叮当就是用jsp页面进行映衬。

代码如下:首先是写jsp页面,将其分成多个块,然后再分块操作:

XML/HTML Code复制内容到剪贴板
  1. <%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>
  2. <%
  3. Stringpath=request.getContextPath();
  4. StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN">
  7. <html>
  8. <head>
  9. <baserel="nofollow noopener noreferrer" href="<%=basePath%>">
  10. <linkrel="stylesheet"type="text/css"rel="nofollow noopener noreferrer" href="bootstrap-3.3.5-dist/css/bootstrap.min.css">
  11. <linkrel="stylesheet"type="text/css"rel="nofollow noopener noreferrer" href="css/DLAM.css">
  12. <title>here</title>
  13. <metahttp-equiv="pragma"content="no-cache">
  14. <metahttp-equiv="cache-control"content="no-cache">
  15. <metahttp-equiv="expires"content="0">
  16. <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3">
  17. <metahttp-equiv="description"content="Thisismypage">
  18. <!--
  19. <linkrel="stylesheet"type="text/css"rel="nofollow noopener noreferrer" href="styles.css">
  20. -->
  21. </head>
  22. <body>
  23. <divclass="doraemon">
  24. <divclass="head">
  25. <divclass="eyes">
  26. <divclass="eyeleft"><divclass="blackbleft"></div></div>
  27. <divclass="eyeright"><divclass="blackbright"></div></div>
  28. </div>
  29. <divclass="face">
  30. <divclass="white"></div>
  31. <divclass="nose"><divclass="light"></div></div>
  32. <divclass="nose_line"></div>
  33. <divclass="mouth"></div>
  34. <divclass="whiskers">
  35. <divclass="whiskerrTopr160"></div>
  36. <divclass="whiskerrt"></div>
  37. <divclass="whiskerrBottomr20"></div>
  38. <divclass="whiskerlTopr20"></div>
  39. <divclass="whiskerlt"></div>
  40. <divclass="whiskerlBottomr160"></div>
  41. </div>
  42. </div>
  43. </div>
  44. <divclass="choker">
  45. <divclass="bell">
  46. <divclass="bell_line"></div>
  47. <divclass="bell_circle"></div>
  48. <divclass="bell_under"></div>
  49. <divclass="bell_light"></div>
  50. </div>
  51. </div>
  52. <divclass="bodys">
  53. <divclass="body"></div>
  54. <divclass="wraps"></div>
  55. <divclass="pocket"></div>
  56. <divclass="pocket_mask"></div>
  57. </div>
  58. <divclass="hand_right">
  59. <divclass="arm"></div>
  60. <divclass="circle"></div>
  61. <divclass="arm_rewrite"></div>
  62. </div>
  63. <divclass="hand_left">
  64. <divclass="arm"></div>
  65. <divclass="circle"></div>
  66. <divclass="arm_rewrite"></div>
  67. </div>
  68. <divclass="foot">
  69. <divclass="left"></div>
  70. <divclass="right"></div>
  71. <divclass="foot_rewrite"></div>
  72. </div>
  73. </div>
  74. </body>
  75. </html>


再接下来就是每一个div的细致描写刻画:

XML/HTML Code复制内容到剪贴板
  1. @CHARSET"UTF-8";
  2. .CC{
  3. font-size:100px;
  4. font-weight:600;
  5. font-family:"华文楷体";
  6. text-align:center;
  7. }
  8. .doraemon{
  9. position:relative;
  10. margin-top:5px;
  11. margin-left:530px;
  12. }
  13. .doraemon.head{
  14. width:320px;
  15. height:300px;
  16. border-radius:150px;
  17. background:#07bbee;
  18. background:-webkit-radial-gradient(righttop,#fff10%,#07bbee20%,#10a6ce75%,#000);
  19. background:-moz-radial-gradient(righttop,#fff10%,#07bbee20%,#10a6ce75%,#000);
  20. background:-ms-radial-gradient(righttop,#fff10%,#07bbee20%,#10a6ce75%,#000);
  21. border:#5552pxsolid;
  22. box-shadow:-5px10px15pxrgba(0,0,0,0.45);
  23. position:relative;
  24. }
  25. .doraemon.face{
  26. position:relative;
  27. z-index:2;
  28. }
  29. .doraemon.face.white{
  30. border:#0002pxsolid;
  31. width:265px;
  32. height:195px;
  33. border-radius:150px150px;
  34. position:absolute;
  35. top:75px;left:25px;
  36. background:#fff;
  37. background:-webkit-radial-gradient(righttop,#fff75%,#eee75%,#eee80%,#99990%,#444);
  38. background:-moz-radial-gradient(righttop,#fff75%,#eee75%,#eee80%,#99990%,#444);
  39. background:-ms-radial-gradient(righttop,#fff10%,#eee75%,#eee80%,#99990%,#444);
  40. }
  41. .doraemon.face.nose{
  42. border:2pxsolid#000;
  43. width:30px;
  44. height:30px;
  45. border-radius:30px;
  46. position:absolute;
  47. background:#c93300;
  48. top:110px;left:140px;
  49. z-index:3;
  50. }
  51. .doraemon.face.nose.light{
  52. border-radius:5px;
  53. box-shadow:19px8px5px#FFF;
  54. width:10px;
  55. height:10px;
  56. }
  57. .doraemon.face.nose_line{
  58. background:#333;
  59. width:3px;
  60. height:100px;
  61. top:140px;left:155px;
  62. position:absolute;
  63. z-index:3;
  64. }
  65. .doraemon.face.mouth{
  66. width:220px;
  67. height:400px;
  68. border-radius:120px;
  69. border-bottom:3pxsolid#333;
  70. position:absolute;
  71. top:-160px;left:45px;
  72. }
  73. .doraemon.eyes{
  74. position:relative;
  75. z-index:3;
  76. }
  77. .doraemon.eyes.eye{
  78. width:72px;
  79. height:82px;
  80. position:absolute;
  81. top:40px;
  82. background:#fff;
  83. border:2pxsolid#000;
  84. border-radius:35px35px;
  85. }
  86. .doraemon.eyes.eye.black{
  87. width:14px;
  88. height:14px;
  89. background:#000;
  90. border-radius:14px;
  91. position:relative;
  92. top:40px;
  93. }
  94. .doraemon.eyes.left{
  95. left:82px;
  96. }
  97. .doraemon.eyes.right{
  98. left:156px;
  99. }
  100. .doraemon.eyes.eye.bleft{
  101. left:50px;
  102. }
  103. .doraemon.eyes.eye.bright{
  104. left:7px;
  105. }
  106. .doraemon.whiskers{
  107. width:220px;
  108. height:80px;
  109. background:#fff;
  110. position:relative;
  111. border-radius:15px;
  112. top:120px;left:45px;
  113. z-index:2;
  114. }
  115. .doraemon.whiskers.whisker{
  116. background:#333;
  117. width:60px;
  118. height:2px;
  119. position:absolute;
  120. z-index:2;
  121. }
  122. .doraemon.whiskers.rTop{
  123. top:25px;left:165px;
  124. }
  125. .doraemon.whiskers.rt{
  126. top:45px;left:167px;
  127. }
  128. .doraemon.whiskers.rBottom{
  129. top:65px;left:165px;
  130. }
  131. .doraemon.whiskers.lTop{
  132. top:25px;left:0px;
  133. }
  134. .doraemon.whiskers.lt{
  135. top:45px;left:-2px;
  136. }
  137. .doraemon.whiskers.lBottom{
  138. top:65px;left:0px;
  139. }
  140. .doraemon.whiskers.r160{
  141. transform:rotate(160deg);
  142. -webkit-transform:rotate(160deg);
  143. }
  144. .doraemon.whiskers.r20{
  145. transform:rotate(20deg);
  146. -webkit-transform:rotate(20deg);
  147. }
  148. .doraemon.choker{
  149. position:relative;
  150. z-index:4;
  151. top:-40px;left:45px;
  152. background:#c40;
  153. background:-webkit-gradient(linear,lefttop,leftbottom,from(#c40),to(#800400));
  154. background:-moz-linear-gradient(centertop,#c40,#800400);
  155. background:-ms-linear-gradient(centertop,#c40,#800400);
  156. border:2pxsolid#000000;
  157. border-radius:10px10px10px10px;
  158. width:230px;
  159. height:20px;
  160. }
  161. .doraemon.choker.bell{
  162. width:40px;
  163. height:40px;
  164. _overflow:hidden;
  165. border-radius:50px;
  166. border:2pxsolid#000;
  167. background:#f9f12a;
  168. background:-webkit-gradient(linear,lefttop,leftbottom,from(#f9f12a),color-stop(0.5,#e9e11a),to(#a9a100));
  169. background:-moz-linear-gradient(top,#f9f12a,#e9e11a75%,#a9a100);
  170. background:-ms-linear-gradient(top,#f9f12a,#e9e11a75%,#a9a100);
  171. box-shadow:-5px5px10pxrgba(0,0,0,0.25);
  172. position:relative;
  173. top:5px;left:90px;
  174. }
  175. .doraemon.choker.bell_line{
  176. background:#c40;
  177. border-radius:3px3px0px0px;
  178. border:2pxsolid#333333;
  179. height:2px;width:36px;
  180. position:relative;
  181. top:10px;
  182. }
  183. .doraemon.choker.bell_circle{
  184. background:#000;
  185. border-radius:5px;
  186. height:10px;width:12px;
  187. position:relative;
  188. top:10px;
  189. left:13px;
  190. }
  191. .doraemon.choker.bell_circle{
  192. background:#000;
  193. border-radius:5px;
  194. height:10px;width:12px;
  195. position:relative;
  196. top:10px;
  197. left:13px;
  198. }
  199. .doraemon.choker.bell_under{
  200. background:#000;
  201. height:15px;width:3px;
  202. top:10px;
  203. left:18px;
  204. position:relative;
  205. }
  206. .doraemon.choker.bell_light{
  207. border-radius:10px;
  208. box-shadow:19px8px5px#fff;
  209. height:11px;width:11px;
  210. position:relative;
  211. top:-34px;
  212. left:4px;
  213. opacity:0.7;
  214. }
  215. .doraemon.bodys{
  216. position:relative;
  217. top:-310px;
  218. }
  219. .doraemon.bodys.body{
  220. background:#07beea;
  221. background:-webkit-gradient(linear,righttop,lefttop,from(#07beea),color-stop(0.5,#0073b3),color-stop(0.75,#00b0e0),to(#0096be));
  222. background:-moz-linear-gradient(rightcenter,#07beea,#0073b350%,#00b0e075%,#0096be100%);
  223. background:-ms-linear-gradient(rightcenter,#07beea,#0073b350%,#00b0e075%,#0096be100%);
  224. border:2pxsolid#333;
  225. height:165px;width:220px;
  226. position:absolute;
  227. top:265px;
  228. left:50px;
  229. }
  230. .doraemon.bodys.wraps{
  231. background:#fff;
  232. background:-webkit-gradient(linear,righttop,leftbottom,from(#fff),color-stop(0.75,#fff),color-stop(0.83,#eee),color-stop(0.90,#999),color-stop(0.95,#444),to(#000));
  233. background:-moz-linear-gradient(righttop,#fff,#fff50%,#eee75%,#eee83%,#99990%,#44495%,#000);
  234. background:-ms-linear-gradient(righttop,#fff,#fff50%,#eee75%,#eee83%,#99990%,#44495%,#000);
  235. border:2pxsolid#000;
  236. border-radius:85px;
  237. position:absolute;
  238. height:170px;width:170px;
  239. top:230px;
  240. left:72px;
  241. }
  242. .doraemon.bodys.pocket{
  243. position:relative;
  244. height:130px;width:130px;
  245. border-radius:65px;
  246. background:#fff;
  247. background:-webkit-gradient(linear,righttop,leftbottom,from(#fff),color-stop(0.70,#fff),color-stop(0.75,#f8f8f8),color-stop(0.80,#eee),color-stop(0.88,#ddd),to(#fff));
  248. background:-moz-linear-gradient(righttop,#fff,#fff70%,#f8f8f875%,#eee80%,#ddd88%,#fff);
  249. background:-ms-linear-gradient(righttop,#fff,#fff70%,#f8f8f875%,#eee80%,#ddd88%,#fff);
  250. border:2pxsolid#000;
  251. top:250px;
  252. left:92px;
  253. }
  254. .doraemon.bodys.pocket_mask{
  255. position:relative;
  256. height:60px;width:134px;
  257. background:#fff;
  258. border-bottom:2pxsolid#000;
  259. top:125px;
  260. left:92px;
  261. }
  262. .doraemon.hand_right{
  263. height:100px;width:100px;
  264. position:absolute;
  265. top:272px;
  266. left:248px;
  267. }
  268. .doraemon.hand_left{
  269. height:100px;width:100px;
  270. position:absolute;
  271. top:272px;
  272. left:-10px;
  273. }
  274. .doraemon.arm{
  275. background:#07beea;
  276. background:-webkit-gradient(linear,lefttop,leftbottom,from(#07beea),color-stop(0.85,#07beea),to(#555));
  277. background:-moz-linear-gradient(centertop,#07beea,#07beea85%,#555);
  278. background:-ms-linear-gradient(centertop,#07beea,#07beea85%,#555);
  279. border:1pxsolid#000000;
  280. position:relative;
  281. height:50px;width:80px;
  282. box-shadow:-10px7px10pxrgba(0,0,0,0.35);
  283. z-index:-1;
  284. }
  285. .doraemon.hand_right.arm{
  286. top:17px;
  287. transform:rotate(35deg);
  288. -webkit-transform:rotate(35deg);
  289. }
  290. .doraemon.hand_left.arm{
  291. top:17px;
  292. background:#0096be;
  293. box-shadow:5px-7px10pxrgba(0,0,0,0.25);
  294. transform:rotate(145deg);
  295. -webkit-transform:rotate(145deg);
  296. }
  297. .doraemon.circle{
  298. background:#fff;
  299. background:-webkit-gradient(linear,righttop,leftbottom,from(#fff),color-stop(0.5,#fff),color-stop(0.7,#eee),color-stop(0.8,#ddd),to(#999));
  300. background:-moz-linear-gradient(righttop,#fff,#fff50%,#eee70%,#ddd80%,#999);
  301. position:absolute;
  302. height:60px;width:60px;
  303. border:2pxsolid#000;
  304. border-radius:30px;
  305. }
  306. .doraemon.hand_right.circle{
  307. left:40px;
  308. top:32px;
  309. }
  310. .doraemon.hand_left.circle{
  311. left:-20px;
  312. top:32px;
  313. }
  314. .doraemon.arm_rewrite{
  315. background:#07beea;
  316. position:relative;
  317. height:45px;width:5px;
  318. }
  319. .doraemon.hand_right.arm_rewrite{
  320. left:20px;
  321. top:-45px;
  322. }
  323. .doraemon.hand_left.arm_rewrite{
  324. left:60px;
  325. top:-45px;
  326. background:#0096be;
  327. }
  328. .doraemon.foot{
  329. height:40px;
  330. left:20px;
  331. position:relative;
  332. top:-141px;
  333. width:280px;
  334. }
  335. .doraemon.foot.left{
  336. background:#fff;
  337. background:-webkit-gradient(linear,righttop,leftbottom,from(#fff),color-stop(0.75,#fff),color-stop(0.85,#eee),to(#999));
  338. background:-moz-linear-gradient(righttop,#fff,#fff75%,#eee85%,#999);
  339. background:-ms-linear-gradient(righttop,#fff,#fff75%,#eee85%,#999);
  340. border:2pxsolid#333;
  341. border-radius:80px60px60px40px;
  342. box-shadow:-6px010pxrgba(0,0,0,0.35);
  343. height:30px;
  344. left:14px;
  345. position:relative;
  346. top:69px;
  347. width:125px;
  348. }
  349. .doraemon.foot.right{
  350. background:#fff;
  351. background:-webkit-gradient(linear,righttop,leftbottom,from(#fff),color-stop(0.75,#fff),color-stop(0.85,#eee),to(#999));
  352. background:-moz-linear-gradient(righttop,#fff,#fff75%,#eee85%,#999);
  353. background:-ms-linear-gradient(righttop,#fff,#fff75%,#eee85%,#999);
  354. border:2pxsolid#333;
  355. border-radius:80px60px60px40px;
  356. box-shadow:-6px010pxrgba(0,0,0,0.35);
  357. height:30px;
  358. left:141px;
  359. position:relative;
  360. top:39px;
  361. width:125px;
  362. }
  363. .doraemon.foot.foot_rewrite{
  364. position:relative;
  365. top:0px;
  366. left:132px;
  367. _left:127px;
  368. width:20px;
  369. height:11px;
  370. background:#fff;
  371. background:-webkit-gradient(linear,righttop,leftbottom,from(#666),color-stop(0.83,#fff),to(#fff));
  372. background:-moz-linear-gradient(righttop,#666,#fff83%,#fff);
  373. background:-ms-linear-gradient(righttop,#666,#fff83%,#fff);
  374. border-top:2pxsolid#000;
  375. border-right:2pxsolid#000;
  376. border-left:2pxsolid#000;
  377. border-top-right-radius:40px;
  378. border-top-left-radius:40px;
  379. }


这个是整体的描绘,接下来,我来根据自己的理解更加深刻地理解每一个特效的来源。

background:-webkit-radial-gradien :这个属性是讲颜色的渐变,比如哆啦A梦的蓝色,从右上再到左下,颜色逐渐加深,线性渐变;

线性渐变实例:

border-radius:转换为圆角;

z-index:指定该元素的层叠顺序,比如说图片,若z-index为-1,覆盖在图片上面的字就会显示出来。

rgba(0,0,0,0.45):表示透明度的;

—overflow:设置当元素的内容溢出其区域时发生的事情,hidden,隐藏。

transform:转换和旋转;

这里还有一个动画效果,目的是让小叮当的眼睛动起来~

CSS Code复制内容到剪贴板
  1. <styletype="text/css">
  2. @-webkit-keyframeseyemove{
  3. 80%{margin:0;}
  4. 85%{margin:-20px000;}
  5. 90%{margin:0000;}
  6. 93%{margin:0007px;}
  7. 96%{margin:0000;}
  8. }
  9. @-webkit-keyframeseyemove{
  10. 80%{margin:0;}
  11. 85%{margin:-20px000;}
  12. 90%{margin:0000;}
  13. 93%{margin:0007px;}
  14. 96%{margin:0000;}
  15. }
  16. @-webkit-keyframeseyemove{
  17. 80%{margin:0;}
  18. 85%{margin:-20px000;}
  19. 90%{margin:0000;}
  20. 93%{margin:0007px;}
  21. 96%{margin:0000;}
  22. }
  23. .doraemon.eyes.eye.black{
  24. -webkit-animation-name:eyemove;
  25. -webkit-animation-duration:5s;
  26. -webkit-animation-timing-function:linear;
  27. -webkit-animation-iteration-count:20000;
  28. -webkit-animation-name:eyemove;
  29. -webkit-animation-duration:5s;
  30. -webkit-animation-timing-function:linear;
  31. -webkit-animation-iteration-count:20000;
  32. -webkit-animation-name:eyemove;
  33. -webkit-animation-duration:5s;
  34. -webkit-animation-timing-function:linear;
  35. -webkit-animation-iteration-count:20000;
  36. }
  37. </style>


最后再来看一看哆啦A梦的最终效果图。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
您可能有感兴趣的文章
CSS画出各种三角形如等边三角形