CSS3大熊貓卡通效果

antzone發表於2018-05-22

分享一段程式碼例項,它實現了卡通效果的大熊貓形象。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
.box {
  margin: 0 auto;
  width: 600px;
  height: 800px;
  background: #8ECC2B;
}
.boxC {
  width: 450px;
  margin: 0 auto;
  overflow: hidden;
}
.box-header {
  width: 350px;
  height: 260px;
  background: #f5f5f5;
  border-radius: 300px 300px 200px 200px;
  margin: 0 auto;
  margin-top: 50px;
  position: relative;
}
.header {
  width: 350px;
  height: 260px;
  background: #f5f5f5;
  border-radius: 300px 300px 200px 200px;
  top: 0;
  position: absolute;
  z-index: 10;
}
.box-body {
  width: 350px;
  height: 250px;
  margin: 0 auto;
  background: #f3f3f3;
  border-radius: 270px 270px 150px 150px;
  position: relative;
}
.box-hand {
  width: 300px;
  height: 150px;
  top: -20px;
  position: relative;
  margin: 0 auto;
  border-radius: 150px;
  overflow: hidden;
  position: relative;
}
.bh-a {
  width: 300px;
  height: 80px;
  border-radius: 16px 22px 43px 57px;
  background: #000;
  position: absolute;
  top: 0;
}
.bh-b {
  width: 80px;
  height: 140px;
  border-radius: 20px 22px 43px 80px;
  background: #000;
  position: absolute;
  left: 0px;
}
.bh-c {
  width: 68px;
  height: 140px;
  border-radius: 16px 22px 43px 30px;
  background: #000;
  position: absolute;
  right: 0px;
}
.bh-d {
  width: 180px;
  height: 60px;
  border-radius: 40px 52px 43px 57px;
  background: #f3f3f3;
  position: absolute;
  top: 70px;
  left: 50%;
  margin-left: -90px;
}
.foot {
  width: 300px;
  height: 100px;
  position: relative;
  margin: 0 auto;
}
.foot-left {
  width: 120px;
  height: 80px;
  position: absolute;
  left: 0px;
  background: #000;
  border-radius: 90px 100px 20px 80px;
  bottom: 0;
}
.foot-right {
  width: 120px;
  height: 80px;
  position: absolute;
  background: #000;
  border-radius: 90px 70px 80px 20px;
  bottom: 0;
  right: -15px;
}
.left-ear {
  position: absolute;
  top: -25px;
  width: 120px;
  height: 80px;
  left: -20px;
  background: #000000;
  -webkit-transform: rotate(-40deg);
  border-radius: 60px 60px 2px 2px;
}
.right-ear {
  position: absolute;
  top: -25px;
  width: 120px;
  height: 80px;
  right: -20px;
  background: #000000;
  -webkit-transform: rotate(40deg);
  border-radius: 60px 60px 2px 2px;
}
.left-eyes {
  position: absolute;
  left: 80px;
  width: 60px;
  height: 80px;
  background: #000;
  border-radius: 30px 20px;
  top: 50px;
  border-radius: 60px 60px 80px 55px;
  -webkit-transform: rotate(20deg);
}
.right-eyes {
  position: absolute;
  right: 80px;
  top: 50px;
  width: 60px;
  height: 80px;
  background: #000;
  border-radius: 60px 60px 55px 80px;
  -webkit-transform: rotate(-20deg);
}
.small-eyes {
  width: 30px;
  height: 30px;
  background: #fff;
  border-radius: 50%;
  margin-top: 28px;
  margin-left: 15px;
  position: relative;
}
.small-eyes:after {
  position: absolute;
  content: '';
  width: 15px;
  height: 15px;
  background: #000;
  border-radius: 50%;
  top: 8px;
  left: 0px;
  -webkit-animation: mymove 2s ease infinite;
}
@-webkit-keyframes mymove {
  0% {
    left: 0px;
  }
  20% {
    left: 6px;
  }
  50% {
    left: 14px;
  }
  80% {
    left: 6px;
  }
  100% {
    left: 0px;
  }
}
.mask {
  text-align: center;
  font-size: 48px;
  color: #FFF;
  text-decoration: double;
  line-height: 200px;
}
.center-nose {
  position: absolute;
  width: 50px;
  height: 30px;
  background: #000;
  border-radius: 50%;
  left: 50%;
  margin-left: -25px;
  top: 118px;
}
.mouse {
  width: 80px;
  height: 50px;
  position: absolute;
  top: 156px;
  margin-left: -40px;
  left: 50%;
  border: 6px solid #000000;
  border-radius: 100%;
}
.mark {
  width: 120px;
  background: #f5f5f5;
  position: absolute;
  height: 30px;
  margin-left: -60px;
  left: 50%;
  z-index: 20;
  top: 156px;
}
</style>
</head>
<body>
  <div class="box">
    <div class="boxC">
      <div class="box-header">
        <div class="header">
          <div class="left-eyes"><div class="small-eyes"></div></div>
          <div class="center-nose"></div>
          <div class="right-eyes"><div class="small-eyes"></div></div>
          <div class="mouse"></div>
          <div class="mark"></div>
        </div>
        <div class="left-ear"></div>
        <div class="right-ear"></div>
      </div>
      <div class="box-body">
        <div class="box-hand">
          <div class="bh-a"></div>
          <div class="bh-b"></div>
          <div class="bh-c"></div>
          <div class="bh-d"></div>
        </div>
        <div class="foot">
          <div class="foot-left"></div>
          <div class="foot-right"></div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>

相關文章