畫一隻會動的皮卡丘(上)

實現的皮卡丘樣式以下圖:

本篇內容List:

tip1--全局樣式初始化,配置
tip2--實現鼻子
tip3--實現眼睛
tip4--實現臉頰
tip5--嘴巴實現

在這裏插入圖片描述

1.先進行頁面總體的樣式配置

這裏咱們要在手機端展現,因此咱們儘可能整個圖形的寬度要小於手機屏幕的最小寬度,代碼以下:

* {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    *::after {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    //設置body樣式使內容居中等
    body {
      width: 100%;
      height: 100vh;
      background-color: yellow;
      border: 1px solid green;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    //爲咱們須要畫圖的主體區域
    .wrapper {
      width: 100%;
      height: 220px;
      position: relative;
    }

2.鼻子的繪畫

利用一個div盒子寬高等於0,而後給予邊寬來撐大盒子,再取消不須要的邊框,就能夠實現一個圓餅的效果,代碼以下

.nose {
      width: 0;
      height: 0;
      border: 11px solid red;
      border-radius: 12px;
      border-color: black transparent transparent transparent;
      position: absolute;
      left: 50%;
      top: 28px;
      transform: translate(-12px);
    }

3.眼睛的繪畫

咱們把相同的眼睛代碼寫在一個class中,左右眼不一樣的樣式分別寫類名來控制,在測量的時候咱們能夠以最中間的鼻子基準來寫代碼,代碼以下;

.eye {
      width: 49px;
      height: 49px;
      background-color: #2E2E2E;
      border-radius: 50%;
      position: absolute;
      border: 2px solid #000;
    }
    .eye::before {
      content: '';
      display: block;
      width: 24px;
      height: 24px;
      background-color: white;
      position: absolute;
      border-radius: 50%;
      left: 6px;
      top: -1px;
      border: 2px solid #000;
    }
    .eye.left {
      right: 50%;
      margin-right: 90px
    }
    .eye.right {
      left: 50%;
      margin-left: 90px
    }

3.臉頰的繪畫

臉頰的繪畫不難,咱們須要準確測量位置,代碼以下:

.face {
      width: 65px;
      height: 68px;
      background-color: #f92726;
      border: 2px solid black;
      border-radius: 50%;
      position: absolute;
      top: 85px;
    }
    .face.left {
      right: 50%;
      margin-right: 116px;
    }
    .face.right {
      left: 50%;
      margin-left: 116px;
    }

4.嘴的繪畫

爲了實現舌頭,結構圖以下;

在這裏插入圖片描述

代碼以下:

.upperLip {
      height: 20px;
      width: 80px;
      border: 3px solid black;
      position: absolute;
      top: 52px;
      background-color: yellow;
      z-index: 1;
    }
  .upperLip.left {
      
      border-bottom-left-radius: 40px 20px;
      border-top: none;
      border-right: none;
      transform: rotate(-20deg);
      right: 50%;
  }
  .upperLip.right {
      left: 50%;
      border-bottom-right-radius: 40px 20px;
      border-top: none;
      border-left: none;
      transform: rotate(20deg);
  }
  .lowerLip-wrapper {
      width: 120px;
      height: 130px;
     
      position: absolute;
      left: 50%;
      margin-left: -60px;
      margin-top: 56px;
      overflow: hidden;
  }
  .lowerLip {
      height: 1000px;
      width: 120px;
      border-radius: 200px/800px;
      border: 2px solid black;
      background-color: #971818;
      position: absolute;
      bottom: 0;
      overflow: hidden
  }
  .tongue {
      width: 100px;
      height: 100px;
      border-radius: 50px;
      left: 8px;
      background-color: #f95364;
      position: absolute;
      bottom: 0;
      z-index: 2;
  }

以上就可實現一個皮卡丘了,現附上整個靜態皮卡丘代碼:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    *::before {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    *::after {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    body {
      width: 100%;
      height: 100vh;
      background-color: yellow;
      border: 1px solid green;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .wrapper {
      width: 100%;
      height: 220px;
     
      position: relative;
    }
    .nose {
      width: 0;
      height: 0;
      border: 11px solid red;
      border-radius: 12px;
      border-color: black transparent transparent transparent;
      position: absolute;
      left: 50%;
      top: 28px;
      transform: translate(-12px);
    }
    .eye {
      width: 49px;
      height: 49px;
      background-color: #2E2E2E;
      border-radius: 50%;
      position: absolute;
      border: 2px solid #000;
    }
    .eye::before {
      content: '';
      display: block;
      width: 24px;
      height: 24px;
      background-color: white;
      position: absolute;
      border-radius: 50%;
      left: 6px;
      top: -1px;
      border: 2px solid #000;
    }
    .eye.left {
      right: 50%;
      margin-right: 90px
    }
    .eye.right {
      left: 50%;
      margin-left: 90px
    }
    .face {
      width: 65px;
      height: 68px;
      background-color: #f92726;
      border: 2px solid black;
      border-radius: 50%;
      position: absolute;
      top: 85px;
    }
    .face.left {
      right: 50%;
      margin-right: 116px;
    }
    .face.right {
      left: 50%;
      margin-left: 116px;
    }
    .upperLip {
      height: 20px;
      width: 80px;
      border: 3px solid black;
      position: absolute;
      top: 52px;
      background-color: yellow;
      z-index: 1;
    }
    .upperLip.left {
      
      border-bottom-left-radius: 40px 20px;
      border-top: none;
      border-right: none;
      transform: rotate(-20deg);
      right: 50%;
    }
    .upperLip.right {
      left: 50%;
      border-bottom-right-radius: 40px 20px;
      border-top: none;
      border-left: none;
      transform: rotate(20deg);
    }
    .lowerLip-wrapper {
      width: 120px;
      height: 130px;
     
      position: absolute;
      left: 50%;
      margin-left: -60px;
      margin-top: 56px;
      overflow: hidden;
    }
    .lowerLip {
      height: 1000px;
      width: 120px;
      border-radius: 200px/800px;
      border: 2px solid black;
      background-color: #971818;
      position: absolute;
      bottom: 0;
      overflow: hidden
    }
    .tongue {
      width: 100px;
      height: 100px;
      border-radius: 50px;
      left: 8px;
      background-color: #f95364;
      position: absolute;
      bottom: 0;
      z-index: 2;
    }
  </style>
</head>
<body>
<div class="wrapper">
  <div class="nose">
  </div>
  <div class="eye left"></div>
  <div class="eye right"></div>
  <div class="face left"></div>  
  <div class="face right"></div>
  <div class="upperLip left"></div>
  <div class="upperLip right"></div>
  <div class="lowerLip-wrapper">
    <div class="lowerLip">
      <div class="tongue"></div>
    </div>
  </div>
</div>
</body>
</html>
相關文章
相關標籤/搜索