1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        用css實(shí)現(xiàn)轉(zhuǎn)動(dòng)的陰陽(yáng)太極圖

        共 40762字,需瀏覽 82分鐘

         ·

        2021-03-23 16:41

        問:如何用css和html畫出旋轉(zhuǎn)的陰陽(yáng)太極圖


        需要的知識(shí)

        • 1.div標(biāo)簽的運(yùn)用
        • 2.id選擇器,后代選擇器,
        • 3.簡(jiǎn)單的css樣式長(zhǎng),寬,高,背景顏色,浮動(dòng),絕對(duì)定位,邊框弧度
        • 4.div的布局特點(diǎn)

        靜態(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>太極頁(yè)面</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部分說明

        通過改變每個(gè)div的大小顏色,浮動(dòng)的left,top值,改變每個(gè)div的border-redius的值來畫這個(gè)八卦圖

        <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>太極頁(yè)面</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>

        注意事項(xiàng)

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

        讓八卦轉(zhuǎn)起來

        /*先定義一個(gè)@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);
                }

        轉(zhuǎn)動(dòng)的八卦完整代碼

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

        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>太極頁(yè)面</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>

        拓展:手機(jī)端的轉(zhuǎn)動(dòng)的八卦

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

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

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

        移動(dòng)端完整代碼

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

        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>太極頁(yè)面</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真是神秘~

        針對(duì)這個(gè)題目,你的解決方案又是什么呢?

        不妨在下面的留言給出,學(xué)習(xí)共勉下~

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

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

        最后

        ?

        有疑問的同學(xué) 歡迎 評(píng)論區(qū)討論,也歡迎大家加入我的前端技術(shù)交流群 來討論。搜索《前端陽(yáng)光》公眾號(hào),回復(fù)加群吧!



        瀏覽 123
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            可以免费看黄的网站 | 精品无码人妻一区二区三区 | 国产乳交| 18久久 | 日本卖婬片免费看 | 电子书乱伦视频 | 日本高清不卡在线视频 | 欧美色逼| 97超碰视屏免费 | 亚洲专区免费 |