<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          用css實現(xiàn)轉動的陰陽太極圖

          共 40762字,需瀏覽 82分鐘

           ·

          2021-03-23 16:41

          問:如何用css和html畫出旋轉的陰陽太極圖


          需要的知識

          • 1.div標簽的運用
          • 2.id選擇器,后代選擇器,
          • 3.簡單的css樣式長,寬,高,背景顏色,浮動,絕對定位,邊框弧度
          • 4.div的布局特點

          靜態(tài)的完成效果

          開始

          HTML部分
          <!DOCTYPE html>
          <html lang="zh">
          <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>太極頁面</title>
          </head>
          <body>
              <div id="八卦-wrapper">
                  <div id="八卦">
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                  </div>
                  <div id="八卦-描述">道可道,非常道</div>
              </div>
          </body>
          </html>
          HTML部分說明(不要吐槽中文id哈哈哈,純屬為了方便講解)
          • 1.其中最外面的id為八卦-wrapper為包住八卦的最大的div
          • 2.id 為八卦的div為上圖中的八卦
          • 3.八卦里面的div為 下圖指示部分

          CSS部分

          CSS部分說明

          通過改變每個div的大小顏色,浮動的left,top值,改變每個div的border-redius的值來畫這個八卦圖

          <style>
                  * {
                      box-sizing: border-box;
                      margin0px;
                      padding0px;
                  }
                  body {
                      background-color#eeeeee;
                  }
                  #八卦 {

                      width400px;
                      height400px;
                      border-radius200px;
                      position: relative;
                      overflow: hidden;
                      animation: x 10s linear infinite;
                      box-shadow0px 0px 5px 0px rgba(0001);
                  }
                  #八卦>div:first-child {
                      width50%;
                      height100%;
                      position: absolute;
                      left0;
                      background-color: black;
                  }

                  #八卦>div:nth-child(2) {
                      width50%;
                      height100%;
                      position: absolute;
                      right0;
                      background-color: white;
                  }
                  #八卦>div:nth-child(3) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: black;
                  }
                  #八卦>div:nth-child(4) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      top50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: white;
                  }
                  #八卦>div:nth-child(5) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      top75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: white;
                  }
                  #八卦>div:nth-child(6) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      bottom75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: black;
                  }
                  #八卦-wrapper {
                      height100vh;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      flex-direction: column;
                  }
                  #八卦-描述 {
                      margin-top1em;
                      font-size3em;
                  }
             </style>

          完整代碼

          <!DOCTYPE html>
          <html lang="zh">

          <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>太極頁面</title>
              <style>
                  * {
                      box-sizing: border-box;
                      margin0px;
                      padding0px;
                  }

                  body {
                      background-color#eeeeee;
                  }


                  #八卦 {

                      width400px;
                      height400px;
                      border-radius200px;
                      position: relative;
                      overflow: hidden;
                      animation: x 10s linear infinite;
                      box-shadow0px 0px 5px 0px rgba(0001);
                  }

               

                  #八卦>div:first-child {
                      width50%;
                      height100%;
                      position: absolute;
                      left0;
                      background-color: black;
                  }

                  #八卦>div:nth-child(2) {

                      width50%;
                      height100%;
                      position: absolute;
                      right0;
                      background-color: white;
                  }

                  #八卦>div:nth-child(3) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: black;
                  }


                  #八卦>div:nth-child(4) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      top50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: white;
                  }

               

                  #八卦>div:nth-child(5) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      top75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: white;
                  }

               

                  #八卦>div:nth-child(6) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      bottom75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: black;
                  }

                

                  #八卦-wrapper {
                      height100vh;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      flex-direction: column;
                  }


                  #八卦-描述 {
                      margin-top1em;
                      font-size3em;
                  }

              
          </style>
          </head>

          <body>
              <div id="八卦-wrapper">
                  <div id="八卦">
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                  </div>
                  <div id="八卦-描述">道可道,非常道</div>
              </div>
          </body>

          </html>

          注意事項

          • 1.id可以用中文 ,但是文件名和路徑不能(最好不要)
          • 2.一定要注意清楚瀏覽其的默認樣式
          • 3.能不寫死就千萬不要寫死,最好用百分比代替像素(防止用戶改變分辨率造成的bug)
          • 4.父元素relative,子元素absolute
          • 5.注意幾個div的偏移位置,可以加boder: 1px,solid,red;來確定位置后調(diào)試
          • 6.第27行代碼為讓八卦轉起來在靜態(tài)八卦中不起作用

          讓八卦轉起來

          /*先定義一個@keyframes 命名為x*/
           @keyframes x {
                      from {
                          transformrotate(0deg);
                      }
                      to {
                          transformrotate(360deg);
                      }
                  }
          /*在id="八卦"中添加樣式  animation: x 10s linear infinite;*/
           #八卦 {

                      width400px;
                      height400px;
                      border-radius200px;
                      position: relative;
                      overflow: hidden;
                      animation: x 10s linear infinite;/*添加此行*/
                      box-shadow0px 0px 5px 0px rgba(0001);
                  }

          轉動的八卦完整代碼

          <!DOCTYPE html>
          <html lang="zh">

          <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>太極頁面</title>
              <style>
                  * {
                      box-sizing: border-box;
                      margin0px;
                      padding0px;
                  }

                  body {
                      background-color#eeeeee;
                  }

            @keyframes x {
                      from {
                          transformrotate(0deg);
                      }

                      to {
                          transformrotate(360deg);
                      }
                  }
                  #八卦 {

                      width400px;
                      height400px;
                      border-radius200px;
                      position: relative;
                      overflow: hidden;
                      animation: x 10s linear infinite;
                      box-shadow0px 0px 5px 0px rgba(0001);
                  }

               

                  #八卦>div:first-child {
                      width50%;
                      height100%;
                      position: absolute;
                      left0;
                      background-color: black;
                  }

                  #八卦>div:nth-child(2) {

                      width50%;
                      height100%;
                      position: absolute;
                      right0;
                      background-color: white;
                  }

                  #八卦>div:nth-child(3) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: black;
                  }


                  #八卦>div:nth-child(4) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      top50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: white;
                  }

               

                  #八卦>div:nth-child(5) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      top75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: white;
                  }

               

                  #八卦>div:nth-child(6) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      bottom75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: black;
                  }

                

                  #八卦-wrapper {
                      height100vh;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      flex-direction: column;
                  }


                  #八卦-描述 {
                      margin-top1em;
                      font-size3em;
                  }

              
          </style>
          </head>

          <body>
              <div id="八卦-wrapper">
                  <div id="八卦">
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                  </div>
                  <div id="八卦-描述">道可道,非常道</div>
              </div>
          </body>

          </html>

          拓展:手機端的轉動的八卦

          在原代碼不變的情況下使用

          @media(max-width:500px){ }來設置移動端的樣式。

          (其中設置的樣式為當在移動端的時候所展現(xiàn)的樣式,沒有在其中設置的樣式默認使用客戶端的樣式)

          移動端完整代碼

          <!DOCTYPE html>
          <html lang="zh">

          <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width, initial-scale=1.0">
              <title>太極頁面</title>
              <style>
                  * {
                      box-sizing: border-box;
                      margin0px;
                      padding0px;
                  }

                  body {
                      background-color#eeeeee;
                  }

                  @keyframes x {
                      from {
                          transformrotate(0deg);
                      }

                      to {
                          transformrotate(360deg);
                      }
                  }

                  #八卦 {

                      width400px;
                      height400px;
                      border-radius200px;
                      position: relative;
                      overflow: hidden;
                      animation: x 10s linear infinite;
                      box-shadow0px 0px 5px 0px rgba(0001);
                  }

                  @media (max-width:500px) {
                      #八卦 {
                          width200px;
                          height200px;
                      }
                  }

                  #八卦>div:first-child {
                      width50%;
                      height100%;
                      position: absolute;
                      left0;
                      background-color: black;
                  }

                  #八卦>div:nth-child(2) {

                      width50%;
                      height100%;
                      position: absolute;
                      right0;
                      background-color: white;
                  }

                  #八卦>div:nth-child(3) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: black;
                  }

                  @media (max-width:500px) {
                      #八卦>div:nth-child(3) {
                          width100px;
                          height100px;
                          margin-left: -50px;
                      }
                  }

                  #八卦>div:nth-child(4) {
                      width200px;
                      height200px;
                      position: absolute;
                      left50%;
                      top50%;
                      margin-left: -100px;
                      border-radius50%;
                      background-color: white;
                  }

                  @media (max-width:500px) {
                      #八卦>div:nth-child(4) {
                          width100px;
                          height100px;
                          margin-left: -50px;
                      }
                  }

                  #八卦>div:nth-child(5) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      top75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: white;
                  }

                  @media (max-width:500px) {
                      #八卦>div:nth-child(5) {
                          width25px;
                          height25px;
                          top37.5px;
                          margin-left: -25px;
                      }
                  }

                  #八卦>div:nth-child(6) {
                      width50px;
                      height50px;
                      position: absolute;
                      left50%;
                      bottom75px;
                      margin-left: -50px;
                      border-radius50%;
                      background-color: black;
                  }

                  @media (max-width:500px) {
                      #八卦>div:nth-child(6) {
                          width25px;
                          height25px;
                          bottom37.5px;
                          margin-left: -25px;
                      }

                  }

                  #八卦-wrapper {
                      height100vh;
                      display: flex;
                      justify-content: center;
                      align-items: center;
                      flex-direction: column;
                  }


                  #八卦-描述 {
                      margin-top1em;
                      font-size3em;
                  }

                  @media (max-width:500px) {
                      #八卦-描述 {
                          margin-top0.5em;
                          font-size1.5em;
                      }
                  }
              
          </style>
          </head>

          <body>
              <div id="八卦-wrapper">
                  <div id="八卦">
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                      <div></div>
                  </div>
                  <div id="八卦-描述">道可道,非常道</div>
              </div>
          </body>

          </html>


          CSS真是神秘~

          針對這個題目,你的解決方案又是什么呢?

          不妨在下面的留言給出,學習共勉下~

          碼字不易,走過路過來個贊可否??先謝謝了!

          ε=ε=ε=┏(゜ロ゜;)┛

          最后

          ?

          有疑問的同學 歡迎 評論區(qū)討論,也歡迎大家加入我的前端技術交流群 來討論。搜索《前端陽光》公眾號,回復加群吧!



          瀏覽 123
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美成人乱码视频 | 草草地址线路①屁屁影院成人 | 青青草成人在线播放 | 无码熟妇人妻Av 无需播放器的AV 五月丁香激情网站 | 一区二区三区视屏 |