CSS3哭臉效果

antzone發表於2018-03-19

分享一段程式碼例項,它利用css3實現了哭臉效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
* {
  margin: 0px;
  padding: 0px;
}
.face {
  position: relative;
  margin: 70px auto;
  text-align: center;
}
.left-eye, .right-eye {
  width: 50px;
  height: 50px;
  background: #000;
  position: relative;
  display: inline-block;
  margin: 20px;
  border-radius: 100%;
}
.left-eye::before {
  content: '';
  position: absolute;
  width: 40px;
  height: 10px;
  top: 0;
  background: #000;
  transform: rotate(-30deg);
  z-index: 1;
  left: -7px;
}
.right-eye::before {
  content: '';
  position: absolute;
  width: 40px;
  height: 10px;
  right: 0;
  background: #000;
  transform: rotate(30deg);
  z-index: 1;
  right: -7px;
}
.left-eye::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 10px;
  top: 10px;
  border-radius: 100%;
  background: #ccc;
}
.right-eye::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  right: 10px;
  top: 10px;
  border-radius: 100%;
  background: #ccc;
}
.left-eye span {
  position: absolute;
  background: #00b3b3;
  width: 20px;
  height: 20px;
  transform: rotate(-45deg);
  display: block;
  top: 70px;
  border-radius: 80% 0 55% 50% / 55% 0 80% 50%;
}
.mouth-hidden {
  height: 20px;
  overflow: hidden;
  margin-top: 30px;
}
.mouth {
  height: 100px;
  width: 100px;
  border: 4px solid #000;
  display: inline-block;
  border-radius: 100%;
}
</style>
</head>
<body>
  <div class="face">
    <div class="eyes">
      <div class="left-eye">
        <span></span>
      </div>
      <div class="right-eye">
      </div>
    </div>
    <div class="mouth-hidden">
      <div class="mouth">
      </div>
    </div>
  </div>
</body>
</html>

上面的程式碼實現了我們的要求,更多內容可以參閱相關閱讀。

相關閱讀:

(1).position參閱css position一章節。

(2).border-radius參閱CSS3 border-radius一章節。

(3).::before參閱CSS E:before/E::before一章節。

(4).transform: rotate()參閱transform: rotate()一章節。

(5).z-index參閱CSS z-index一章節。

相關文章