「兔了个兔」玉兔新春,与小兔兔一起恭贺新年吧!(附源码)

218 阅读5分钟

我正在参加「兔了个兔」创意投稿大赛,详情请看:「兔了个兔」创意投稿大赛


前言

各位小伙伴们大家好呀,先在这里祝大家新春快乐!今天让我们与小兔兔一起恭贺新年吧!


效果演示

image.png

实现思路

  看完效果图后,各位小伙伴们肯定很想知道实现的思路,接下来我将分步骤逐一进行讲解。

我将实现思路分成了如下五个部分,列举如下:

  • 背景设计
  • 新年贺词设计
  • 复活蛋设计
  • 小兔头部设计
  • 小兔手部设计

使兔子耳朵动起来主要使用了:after:before伪元素组件。

 背景设计

image.png

  HTML代码

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CSS3复活节兔子代码</title>
  <style>
  </style>
</head>
<body>
<!-- partial:index.partial.html -->
<div class="container">
</div>
<!-- partial -->
  
</body>
</html>

  CSS代码

  将下面代码复制粘贴至<style></style>标签之间

 * {
  margin: 0px;
  padding: 0px;
}

body {
  background-color: #92D0CD;
}

.container {
  width: 700px;
  margin: 40px auto 0px auto;
  text-align: center;
}

 新年贺词设计

image.png

  HTML代码

  将下面代码复制粘贴至<div class="container"></div>标签之间

 <h1>Happy New Year!</h1>

  CSS代码

  将下面代码复制粘贴至<style></style>标签之间

.container h1 {
  font-family: "Lobster Two", cursive;
  font-size: 45px;
  color: #ef4154;
  text-shadow: 3px 0px 0px white;
  margin-bottom: 50px;
}

 复活蛋设计

image.png

  HTML代码

  将下面代码复制粘贴至<h1></h1>标签下方

<div class="bunny-icon">
    <div class="egg"></div>
  </div>

  CSS代码

  将下面代码复制粘贴至<style></style>标签之间

.bunny-icon {
  height: 294px;
  width: 260px;
  margin: auto;
  position: relative;
}
.bunny-icon .egg {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 199px;
  width: 165px;
}
.bunny-icon .egg:before {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 30px;
  background-color: #81c3bf;
  border-radius: 50%;
}
.bunny-icon .egg:after {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  bottom: 11px;
  width: 126px;
  height: 188px;
  background: #FBCED3;
  border-top-left-radius: 50% 58%;
  border-top-right-radius: 50% 58%;
  border-bottom-left-radius: 50% 40%;
  border-bottom-right-radius: 50% 40%;
  background-image: radial-gradient(#ef4154 3px, transparent 0), radial-gradient(#ef4154 5px, transparent 0);
  background-size: 30px 30px;
  background-position: 0 0, 15px 15px;
  z-index: 5;
}

 小兔头部设计

image.png

  HTML代码

  将下面代码复制粘贴至<div class="egg"></div>标签下方

<div class="bunny">
      <div class="head">
        <div class="ears">
          <div class="ear ear-left"></div>
          <div class="ear ear-right"></div>
        </div>
        <div class="face">
          <div class="eyes"></div>
          <div class="nose"></div>
          <div class="mouth"></div>
          <div class="blush"></div>
        </div>
      </div>
    </div>

  CSS代码

  将下面代码复制粘贴至<style></style>标签之间

.bunny-icon .bunny {
  position: absolute;
  top: 0;
  left: 0;
  height: 195px;
  width: 204px;
}
.bunny-icon .bunny .head {
  width: 88px;
  height: 80px;
  transform: rotate(-45deg);
  position: absolute;
  top: 70px;
  right: 20px;
}
.bunny-icon .bunny .head:before {
  content: "";
  display: block;
  position: absolute;
  top: 0px;
  left: 0px;
  background-color: #fff;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  z-index: 3;
}
.bunny-icon .bunny .head .ears {
  position: absolute;
  top: -80px;
  left: 0px;
  width: 90px;
  height: 100px;
  z-index: 1;
}
@keyframes ear-left-animation {
  0% {
    transform: rotate(-30deg);
  }
  100% {
    transform: rotate(-25deg);
  }
}
@keyframes ear-right-animation {
  0% {
    transform: rotate(30deg);
  }
  100% {
    transform: rotate(25deg);
  }
}
.bunny-icon .bunny .head .ears .ear {
  height: 100%;
  width: 45px;
  background-color: #fff;
  border-radius: 50%;
}
.bunny-icon .bunny .head .ears .ear:before {
  content: "";
  display: block;
  height: 70px;
  width: 30px;
  background-color: #FBCED3;
  border-radius: 50%;
}
.bunny-icon .bunny .head .ears .ear-left {
  position: absolute;
  top: 11px;
  left: 0px;
  transform: rotate(-30deg);
  animation: ear-left-animation 0.7s linear 0s infinite alternate;
  transform-origin: center bottom;
}
.bunny-icon .bunny .head .ears .ear-left:before {
  position: absolute;
  top: 20px;
  left: 7px;
}
.bunny-icon .bunny .head .ears .ear-right {
  position: absolute;
  top: 11px;
  right: 0px;
  transform: rotate(30deg);
  animation: ear-right-animation 0.7s linear 0s infinite alternate;
  transform-origin: center bottom;
}
.bunny-icon .bunny .head .ears .ear-right:before {
  position: absolute;
  top: 20px;
  left: 7px;
}
.bunny-icon .bunny .head .face {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  width: 50px;
  height: 60px;
  margin: auto;
  z-index: 4;
}
.bunny-icon .bunny .head .face .eyes {
  width: 30px;
  position: absolute;
  top: 0px;
  left: 0;
  right: 0;
  margin: auto;
  height: 16px;
}
.bunny-icon .bunny .head .face .eyes:before, .bunny-icon .bunny .head .face .eyes:after {
  content: "";
  display: block;
  width: 6px;
  height: 100%;
  background-color: #4B4B4B;
  border-radius: 50%;
  border: 1px solid black;
  box-sizing: border-box;
}
.bunny-icon .bunny .head .face .eyes:before {
  position: absolute;
  top: 0px;
  left: 0;
}
.bunny-icon .bunny .head .face .eyes:after {
  position: absolute;
  top: 0px;
  right: 0;
}
.bunny-icon .bunny .head .face .nose {
  width: 14px;
  height: 7px;
  position: absolute;
  top: 21px;
  left: 0;
  right: 0;
  margin: auto;
}
.bunny-icon .bunny .head .face .nose:before, .bunny-icon .bunny .head .face .nose:after {
  content: "";
  display: block;
  height: 0;
  width: 0;
}
.bunny-icon .bunny .head .face .nose:before {
  position: absolute;
  top: 0px;
  left: 0;
  border: 7px solid transparent;
  border-top: 7px solid black;
}
.bunny-icon .bunny .head .face .nose:after {
  position: absolute;
  top: 1px;
  left: 2px;
  border: 5px solid transparent;
  border-top: 5px solid #4B4B4B;
}
.bunny-icon .bunny .head .face .mouth {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  width: 2px;
  height: 32px;
  margin: auto;
  width: 15px;
  height: 32px;
  margin: auto;
  border-bottom: 2px solid black;
  border-radius: 10px;
}
.bunny-icon .bunny .head .face .mouth:before {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0px;
  width: 2px;
  height: 7px;
  margin: auto;
  background-color: black;
}
.bunny-icon .bunny .head .face .blush {
  position: absolute;
  top: 19px;
  left: 0;
  width: 100%;
  height: 6px;
}
.bunny-icon .bunny .head .face .blush:before, .bunny-icon .bunny .head .face .blush:after {
  content: "";
  display: block;
  width: 13px;
  height: 100%;
  background-color: #FBCED3;
  border-radius: 50%;
}
.bunny-icon .bunny .head .face .blush:before {
  position: absolute;
  top: 0;
  left: 0;
}
.bunny-icon .bunny .head .face .blush:after {
  position: absolute;
  top: 0;
  right: 0;
}

 小兔手部设计

image.png

  HTML代码

  将下面代码复制粘贴至倒数第三个</div>标签上方

<div class="paws"></div>

  CSS代码

  将下面代码复制粘贴至<style></style>标签之间

.bunny-icon .bunny .paws {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 6;
}
.bunny-icon .bunny .paws:before, .bunny-icon .bunny .paws:after {
  content: "";
  display: block;
  width: 20px;
  height: 14px;
  border-radius: 50%;
  background-color: #fff;
}
.bunny-icon .bunny .paws:before {
  position: absolute;
  top: 87px;
  right: 0;
}
.bunny-icon .bunny .paws:after {
  position: absolute;
  right: 58px;
  bottom: 10px;
  transform: rotate(90deg);
}

完整源码

<!DOCTYPE html>
<html lang="en" >
<head>
  <meta charset="UTF-8">
  <title>CSS3复活节兔子代码</title>
 <style>
 * {
  margin: 0px;
  padding: 0px;
}

body {
  background-color: #92D0CD;
}

.container {
  width: 700px;
  margin: 40px auto 0px auto;
  text-align: center;
}
.container h1 {
  font-family: "Lobster Two", cursive;
  font-size: 45px;
  color: #ef4154;
  text-shadow: 3px 0px 0px white;
  margin-bottom: 50px;
}

.bunny-icon {
  height: 294px;
  width: 260px;
  margin: auto;
  position: relative;
}
.bunny-icon .egg {
  position: absolute;
  right: 0;
  bottom: 0;
  height: 199px;
  width: 165px;
}
.bunny-icon .egg:before {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 30px;
  background-color: #81c3bf;
  border-radius: 50%;
}
.bunny-icon .egg:after {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  bottom: 11px;
  width: 126px;
  height: 188px;
  background: #FBCED3;
  border-top-left-radius: 50% 58%;
  border-top-right-radius: 50% 58%;
  border-bottom-left-radius: 50% 40%;
  border-bottom-right-radius: 50% 40%;
  background-image: radial-gradient(#ef4154 3px, transparent 0), radial-gradient(#ef4154 5px, transparent 0);
  background-size: 30px 30px;
  background-position: 0 0, 15px 15px;
  z-index: 5;
}
.bunny-icon .bunny {
  position: absolute;
  top: 0;
  left: 0;
  height: 195px;
  width: 204px;
}
.bunny-icon .bunny .head {
  width: 88px;
  height: 80px;
  transform: rotate(-45deg);
  position: absolute;
  top: 70px;
  right: 20px;
}
.bunny-icon .bunny .head:before {
  content: "";
  display: block;
  position: absolute;
  top: 0px;
  left: 0px;
  background-color: #fff;
  border-radius: 50%;
  width: 100%;
  height: 100%;
  z-index: 3;
}
.bunny-icon .bunny .head .ears {
  position: absolute;
  top: -80px;
  left: 0px;
  width: 90px;
  height: 100px;
  z-index: 1;
}
@keyframes ear-left-animation {
  0% {
    transform: rotate(-30deg);
  }
  100% {
    transform: rotate(-25deg);
  }
}
@keyframes ear-right-animation {
  0% {
    transform: rotate(30deg);
  }
  100% {
    transform: rotate(25deg);
  }
}
.bunny-icon .bunny .head .ears .ear {
  height: 100%;
  width: 45px;
  background-color: #fff;
  border-radius: 50%;
}
.bunny-icon .bunny .head .ears .ear:before {
  content: "";
  display: block;
  height: 70px;
  width: 30px;
  background-color: #FBCED3;
  border-radius: 50%;
}
.bunny-icon .bunny .head .ears .ear-left {
  position: absolute;
  top: 11px;
  left: 0px;
  transform: rotate(-30deg);
  animation: ear-left-animation 0.7s linear 0s infinite alternate;
  transform-origin: center bottom;
}
.bunny-icon .bunny .head .ears .ear-left:before {
  position: absolute;
  top: 20px;
  left: 7px;
}
.bunny-icon .bunny .head .ears .ear-right {
  position: absolute;
  top: 11px;
  right: 0px;
  transform: rotate(30deg);
  animation: ear-right-animation 0.7s linear 0s infinite alternate;
  transform-origin: center bottom;
}
.bunny-icon .bunny .head .ears .ear-right:before {
  position: absolute;
  top: 20px;
  left: 7px;
}
.bunny-icon .bunny .head .face {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  width: 50px;
  height: 60px;
  margin: auto;
  z-index: 4;
}
.bunny-icon .bunny .head .face .eyes {
  width: 30px;
  position: absolute;
  top: 0px;
  left: 0;
  right: 0;
  margin: auto;
  height: 16px;
}
.bunny-icon .bunny .head .face .eyes:before, .bunny-icon .bunny .head .face .eyes:after {
  content: "";
  display: block;
  width: 6px;
  height: 100%;
  background-color: #4B4B4B;
  border-radius: 50%;
  border: 1px solid black;
  box-sizing: border-box;
}
.bunny-icon .bunny .head .face .eyes:before {
  position: absolute;
  top: 0px;
  left: 0;
}
.bunny-icon .bunny .head .face .eyes:after {
  position: absolute;
  top: 0px;
  right: 0;
}
.bunny-icon .bunny .head .face .nose {
  width: 14px;
  height: 7px;
  position: absolute;
  top: 21px;
  left: 0;
  right: 0;
  margin: auto;
}
.bunny-icon .bunny .head .face .nose:before, .bunny-icon .bunny .head .face .nose:after {
  content: "";
  display: block;
  height: 0;
  width: 0;
}
.bunny-icon .bunny .head .face .nose:before {
  position: absolute;
  top: 0px;
  left: 0;
  border: 7px solid transparent;
  border-top: 7px solid black;
}
.bunny-icon .bunny .head .face .nose:after {
  position: absolute;
  top: 1px;
  left: 2px;
  border: 5px solid transparent;
  border-top: 5px solid #4B4B4B;
}
.bunny-icon .bunny .head .face .mouth {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  width: 2px;
  height: 32px;
  margin: auto;
  width: 15px;
  height: 32px;
  margin: auto;
  border-bottom: 2px solid black;
  border-radius: 10px;
}
.bunny-icon .bunny .head .face .mouth:before {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0px;
  width: 2px;
  height: 7px;
  margin: auto;
  background-color: black;
}
.bunny-icon .bunny .head .face .blush {
  position: absolute;
  top: 19px;
  left: 0;
  width: 100%;
  height: 6px;
}
.bunny-icon .bunny .head .face .blush:before, .bunny-icon .bunny .head .face .blush:after {
  content: "";
  display: block;
  width: 13px;
  height: 100%;
  background-color: #FBCED3;
  border-radius: 50%;
}
.bunny-icon .bunny .head .face .blush:before {
  position: absolute;
  top: 0;
  left: 0;
}
.bunny-icon .bunny .head .face .blush:after {
  position: absolute;
  top: 0;
  right: 0;
}
.bunny-icon .bunny .paws {
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 6;
}
.bunny-icon .bunny .paws:before, .bunny-icon .bunny .paws:after {
  content: "";
  display: block;
  width: 20px;
  height: 14px;
  border-radius: 50%;
  background-color: #fff;
}
.bunny-icon .bunny .paws:before {
  position: absolute;
  top: 87px;
  right: 0;
}
.bunny-icon .bunny .paws:after {
  position: absolute;
  right: 58px;
  bottom: 10px;
  transform: rotate(90deg);
}
 </style>
</head>
<body>
<!-- partial:index.partial.html -->
<div class="container">
  <h1>Happy New Year!</h1>
  <div class="bunny-icon">
    <div class="egg"></div>
    <div class="bunny">
      <div class="head">
        <div class="ears">
          <div class="ear ear-left"></div>
          <div class="ear ear-right"></div>
        </div>
        <div class="face">
          <div class="eyes"></div>
          <div class="nose"></div>
          <div class="mouth"></div>
          <div class="blush"></div>
        </div>
      </div>
      <div class="paws"></div>
    </div>
  </div>
</div>
<!-- partial -->
  
</body>
</html>

码上掘金

写在最后的话

  本文花费大量时间介绍了一个可爱的恭贺新年的小兔!希望能帮助到各位小伙伴,码文不易,还望各位大佬们多多支持哦,你们的支持是我最大的动力!

在这里插入图片描述

原创不易,还希望各位大佬支持一下\textcolor{blue}{原创不易,还希望各位大佬支持一下}
👍 点赞,你的认可是我创作的动力!\textcolor{9c81c1}{点赞,你的认可是我创作的动力!}
⭐️ 收藏,你的青睐是我努力的方向!\textcolor{ed7976}{收藏,你的青睐是我努力的方向!}
✏️ 评论,你的意见是我进步的财富!\textcolor{98c091}{评论,你的意见是我进步的财富!}