CSS 绘制圣诞老人

mengkun 34.6K 32

今天的这段代码来源于 Ant Design 不知道还有没有人记得去年闹得轰轰烈烈的圣诞彩蛋事件:

CSS 绘制圣诞老人

当所有人都在吃瓜看戏时,我发现 Ant Design 官网上的这个圣诞老人还挺可爱的……于是就给保存了下来……又是一年圣诞节,终于能派上用场了!

CSS 绘制圣诞老人

效果预览

完整代码

HTML
  1. <style>
  2. .santa-body {
  3. font-size: 80px; /* 试试改变这里的字体大小,有惊喜! */
  4. color: #f91047;
  5. display: -webkit-box;
  6. display: -webkit-flex;
  7. display: -ms-flexbox;
  8. display: flex;
  9. -webkit-box-pack: center;
  10. -webkit-justify-content: center;
  11. -ms-flex-pack: center;
  12. justify-content: center;
  13. -webkit-box-align: center;
  14. -webkit-align-items: center;
  15. -ms-flex-align: center;
  16. align-items: center;
  17. width: 1em;
  18. height: 1em;
  19. background-color: currentColor;
  20. -webkit-box-shadow: inset 0 -0.25em rgba(0,0,0,0.1);
  21. box-shadow: inset 0 -0.25em rgba(0,0,0,0.1);
  22. border-radius: 50%;
  23. -webkit-transform-origin: center bottom;
  24. -ms-transform-origin: center bottom;
  25. transform-origin: center bottom;
  26. -webkit-animation: balance alternate infinite 2s ease-in-out;
  27. animation: balance alternate infinite 2s ease-in-out;
  28. }
  29.  
  30. .santa-head {
  31. font-size: .4em;
  32. width: 1em;
  33. height: 1.9em;
  34. background-color: white;
  35. border-radius: .5em;
  36. -webkit-transform: translateY(-1em);
  37. -ms-transform: translateY(-1em);
  38. transform: translateY(-1em);
  39. position: relative;
  40. }
  41.  
  42. .santa-head::before {
  43. content: '';
  44. width: 1em;
  45. height: .375em;
  46. display: block;
  47. background-color: #ff9876;
  48. position: absolute;
  49. left: 0;
  50. top: .65em;
  51. }
  52.  
  53. .santa-ear {
  54. background-color: #fc8363;
  55. width: .1em;
  56. height: .3em;
  57. position: absolute;
  58. top: .75em;
  59. }
  60.  
  61. .santa-ear:nth-of-type(1) {
  62. border-radius: .05em 0 0 .05em;
  63. left: -0.1em;
  64. }
  65.  
  66. .santa-ear:nth-of-type(2) {
  67. border-radius: 0 .05em .05em 0;
  68. right: -0.1em;
  69. }
  70.  
  71. .santa-hat {
  72. content: '';
  73. width: 1em;
  74. height: .15em;
  75. position: absolute;
  76. -webkit-transform: scale(1.1);
  77. -ms-transform: scale(1.1);
  78. transform: scale(1.1);
  79. top: .5em;
  80. left: 0;
  81. background-color: white;
  82. }
  83.  
  84. .santa-hat::before {
  85. content: '';
  86. display: block;
  87. width: 1em;
  88. height: .5em;
  89. background: #f91047;
  90. border-radius: .5em .5em 0 0;
  91. z-index: 2;
  92. position: absolute;
  93. top: -0.5em;
  94. }
  95.  
  96. .santa-hat::after {
  97. content: '';
  98. width: .25em;
  99. height: .25em;
  100. display: block;
  101. background-color: white;
  102. border-radius: 50%;
  103. position: absolute;
  104. z-index: 0;
  105. top: -0.72em;
  106. right: 0;
  107. -webkit-box-shadow: -0.2em .2em 0 .12em rgba(0,0,0,0.2),-0.2em .2em 0 .12em #f91047;
  108. box-shadow: -0.2em .2em 0 .12em rgba(0,0,0,0.2),-0.2em .2em 0 .12em #f91047;
  109. }
  110.  
  111. .santa-eye {
  112. width: .12em;
  113. height: .12em;
  114. background-color: black;
  115. border-radius: 50%;
  116. position: absolute;
  117. top: .76em;
  118. left: .2em;
  119. }
  120.  
  121. .santa-eye+.santa-eye {
  122. left: auto;
  123. right: .2em;
  124. }
  125.  
  126. .santa-nose {
  127. width: .12em;
  128. height: .22em;
  129. background-color: #f24c4c;
  130. border-radius: 0 0 .12em .12em;
  131. position: absolute;
  132. top: .84em;
  133. left: 50%;
  134. -webkit-transform: translateX(-50%);
  135. -ms-transform: translateX(-50%);
  136. transform: translateX(-50%);
  137. }
  138.  
  139. .santa-mouth {
  140. width: .18em;
  141. height: .1em;
  142. border-bottom-right-radius: 5vw;
  143. border-bottom-left-radius: 5vw;
  144. margin-top: .3em;
  145. background-color: black;
  146. position: absolute;
  147. left: 50%;
  148. top: 50%;
  149. -webkit-transform: translate(-50%, -50%);
  150. -ms-transform: translate(-50%, -50%);
  151. transform: translate(-50%, -50%);
  152. -webkit-animation: hohoho 4s linear forwards infinite;
  153. animation: hohoho 4s linear forwards infinite;
  154. }
  155.  
  156. @-webkit-keyframes hohoho {
  157. 0%,10%,20%,40%,100% {
  158. width: .18em;
  159. height: .1em;
  160. border-bottom-right-radius: 1vw;
  161. border-bottom-left-radius: 1vw;
  162. }
  163.  
  164. 5%,15%,25%,35% {
  165. width: .15em;
  166. height: .2em;
  167. border-radius: 50%;
  168. }
  169. }
  170.  
  171. @keyframes hohoho {
  172. 0%,10%,20%,40%,100% {
  173. width: .18em;
  174. height: .1em;
  175. border-bottom-right-radius: 1vw;
  176. border-bottom-left-radius: 1vw;
  177. }
  178.  
  179. 5%,15%,25%,35% {
  180. width: .15em;
  181. height: .2em;
  182. border-radius: 50%;
  183. }
  184. }
  185.  
  186. @-webkit-keyframes balance {
  187. from {
  188. -webkit-transform: rotate(-4deg);
  189. transform: rotate(-4deg);
  190. }
  191.  
  192. to {
  193. -webkit-transform: rotate(4deg);
  194. transform: rotate(4deg);
  195. }
  196. }
  197.  
  198. @keyframes balance {
  199. from {
  200. -webkit-transform: rotate(-4deg);
  201. transform: rotate(-4deg);
  202. }
  203.  
  204. to {
  205. -webkit-transform: rotate(4deg);
  206. transform: rotate(4deg);
  207. }
  208. }
  209. </style>
  210.  
  211. <div class="santa">
  212. <div class="santa-body">
  213. <div class="santa-head">
  214. <div class="santa-ear"></div>
  215. <div class="santa-ear"></div>
  216. <div class="santa-hat"></div>
  217. <div class="santa-eye"></div>
  218. <div class="santa-eye"></div>
  219. <div class="santa-nose"></div>
  220. <div class="santa-mouth"></div>
  221. </div>
  222. </div>
  223. </div>
运行 复制 文本 高亮

发表评论 取消回复
表情 图片 链接 代码

  1. 烨然Hvril
    烨然Hvril Lv 1

    运行时有偏移

  2. 逼逼
    逼逼 Lv 2

    并且他的Christmas还打错了,Ho ho ho就更不应该了,很多按钮都换上这个了,大家都敏感

  3. 逼逼
    逼逼 Lv 2

    你还觉得antd的圣诞很好?很多人严肃的地方都被他搅局了,就因为没有看他代码,他还说做好了被骂的准备,很多人都投诉,但他没有预先通知还说要自己改,最终才认错的,你还用他的laji东西?

  4. 马修
    马修 Lv 1

    大佬强啊

  5. esnows
    esnows Lv 1

    请问圣诞老人的位置怎么调整呢?现在在左上角,帽子没显示出来。哈哈

    • 味黔城
      味黔城 Lv 1

      @esnows你在顶部加 <br><br><center>然后在代码最后加上 </center>

    • 逼逼
      逼逼 Lv 2

      @esnows用top 属性

  6. iMin博客
    iMin博客 Lv 1

    哈哈,来参观了

  7. 异星软件空间
    异星软件空间 Lv 1

    这个可爱,有点意思!

  8. Ruby
    Ruby Lv 1

    老铁,你的Runcode怎么实现的,请教

  9. 蓝色创想
    蓝色创想 Lv 1

    一个不倒翁圣诞老人

  10. 雨年
    雨年 Lv 1

    大佬np

  11. ych-template
    ych-template Lv 3

    话说大佬,跪求阿鲁表情包

  12. 嘟嘟
    嘟嘟 Lv 1

    大佬膜拜你好久了,能加个友情链接吗

  13. S·c
    S·c Lv 1

    求解github怎么吸引人关注

  14. 365cent
    365cent Lv 3

    Anti design? Ant design? 傻傻分不清
    不过还挺好玩

  15. 穷
    Lv 1

    这可还行

  16. go T
    go T Lv 1

    笑死

  17. 杰新博客
    杰新博客 Lv 3

    2020第一次回复

  18. Xin
    Xin Lv 1

    支持

  19. 一朵白小云
    一朵白小云 Lv 1

    来看望大佬啦

  20. 混迹博客
    混迹博客 Lv 1

    哈哈哈,再来探望大佬

  21. 小铭同学
    小铭同学 Lv 1

    奥利给

  22. 杰新博客
    杰新博客 Lv 3

    哈哈哈,再来探望大佬

  23. 小米博客
    小米博客 Lv 1

    挺不错的

  24. 轩沫说
    轩沫说 Lv 4

    那个愚人节彩蛋还是忘不了。。

  25. 归零幻想
    归零幻想 Lv 1

    感觉有点鞭尸的意味……
    不过有一说一的确挺可爱的。