婷婷久久综合九色综合,欧美成色婷婷在线观看视频,偷窥视频一区,欧美日本一道道一区二区

<tt id="bu9ss"></tt>
  • <span id="bu9ss"></span>
  • <pre id="bu9ss"><tt id="bu9ss"></tt></pre>
    <label id="bu9ss"></label>

    當(dāng)前位置:首頁(yè) >  站長(zhǎng) >  編程技術(shù) >  正文

    HTML+Sass實(shí)現(xiàn)HambergurMenu漢堡包式菜單

     2020-11-30 14:15  來(lái)源: 腳本之家   我來(lái)投稿 撤稿糾錯(cuò)

      阿里云優(yōu)惠券 先領(lǐng)券再下單

    這篇文章主要介紹了HTML+Sass實(shí)現(xiàn)HambergurMenu,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

    前幾天看了國(guó)外一個(gè)大佬用HTML+CSS實(shí)現(xiàn)HamburgerMenu的視頻,然后最近在看Sass,所以用Sass來(lái)實(shí)現(xiàn)一下。

    在VS Code中的文件結(jié)構(gòu)(編譯scss文件用的是easy sass):

    頁(yè)面結(jié)構(gòu)(index.html):

    _config.scss:

    /*設(shè)置顏色及max-width*/
    $primary-color: rgba(13,110,139,.75);
    $overlay-color: rgba(24,39,51,.85);
    $max-width: 980px;

    /*設(shè)置文本顏色,如果背景色淺,則設(shè)置為黑色,否則設(shè)置為白色*/
    @function set-text-color($color){
      @if(lightness($color)>70){
        @return #333;
      }@else{
        @return #fff;
      }
    }

    /*混合器,設(shè)置背景色及文本顏色*/
    @mixin set-background($color){
      background-color: $color;
      color: set-text-color($color);
    }

    style.scss:

    @import '_config';
    *{
      margin: 0;
      padding: 0;
    }

    .container{
      max-width: $max-width;
      margin: 0 auto;
    }

    /*給showcase設(shè)置背景顏色,利用偽類(lèi)再添加一個(gè)背景圖,同時(shí)將背景圖的z-index設(shè)置為-1(這樣圖片會(huì)顯示在里面);
    然后為了讓文字顯示在中間,所以使用flex布局*/
    .showcase{
      position: relative;
      height: 100vh;
      background-color: $primary-color;
      &:before{
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: url('../img/pexels-photo-533923.jpeg') no-repeat center center / cover;
        z-index: -1;
      }
      &-inner{
        display: flex;
        height: 100%;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        color: #fff;
        font-weight: 100;
        h1{
          font-size: 4rem;
          padding: 1.2rem 0;
        }
        p{
          white-space: pre-wrap;
          font-size: 1.6rem;
          padding: 0.85rem 0;
        }
        .btn{
          padding: .65rem 1rem;
            /*使用混合器設(shè)置背景色及文本顏色*/
          @include set-background(lighten($primary-color,30%));
          border: none;
          border: 1px solid $primary-color;
          border-radius: 5px;
          text-decoration: none;
          outline: none;
          transition: all .2s ease .1s;
            /*按鈕hover的時(shí)候利用css3的scale設(shè)置一個(gè)縮放效果*/
          &:hover{
            @include set-background(lighten($overlay-color,30%));
            border-color: lighten($overlay-color, 25%);
            transform: scale(.98);
          }
        }
      }
    }

    /*原理:通過(guò)checkbox的點(diǎn)中與否來(lái)進(jìn)行樣式的變化(將checkbox透明度設(shè)置為0,z-index設(shè)置更高),單擊時(shí),會(huì)出現(xiàn)菜單,再次點(diǎn)擊,菜單消失*/
    /*給menu-wrap設(shè)置fixed,這樣showcase就會(huì)占滿(mǎn)整個(gè)屏幕;同時(shí)將checkbox的opacity設(shè)置為0;
    另外注意,需要將checkbox的z-index設(shè)置為2,因?yàn)閔amburger的z-index設(shè)置為1,不然會(huì)點(diǎn)擊不起作用
    */
    .menu-wrap{
      position: fixed;
      left: 0;
      top: 0;
      z-index: 1;
      .toggle{
        position: absolute;
        left: 0;
        top: 0;
        width: 50px;
        height: 50px;
        opacity: 0;
        z-index: 2;
        cursor: pointer;
          /*當(dāng)checkbox為checked時(shí),設(shè)置hamburger里面的div及偽類(lèi)的旋轉(zhuǎn)效果*/
        &:checked ~ .hamburger>div{
          transform: rotate(135deg);
            /*偽類(lèi)實(shí)際上旋轉(zhuǎn)了225度,需要將top設(shè)置為0,不然形成的?長(zhǎng)短不一致*/
          &:before,&:after{
            transform: rotate(90deg);
            top: 0;
          }
        }

          /*當(dāng)checkbox選中時(shí)再hover,也會(huì)設(shè)置一個(gè)旋轉(zhuǎn)效果*/
        &:checked:hover ~ .hamburger>div{
          transform: rotate(235deg);
        }
        &:checked ~ .menu{
          visibility: visible;
          >div{
            transform: scale(1);
            >div{
              opacity: 1;
            }
          }
        }
      }
       
      .hamburger{
        position: absolute;
        left: 0;
        top: 0;
        width: 60px;
        height: 60px;
        padding: 1rem;
        background-color: $primary-color;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
        z-index: 1;
          /*div自身生成中間的橫線,然后設(shè)置定位為relative,后面再將其偽類(lèi)設(shè)置為absolute,
          相對(duì)于div進(jìn)行偏移*/
        >div{
          position: relative;
          left: 0;
          top: 0;
          width: 100%;
          height: 2px;
          background-color: #fff;
          transition: all .7s ease;
            /*利用偽類(lèi)生成第一條和第三條橫線*/
          &:before,
          &:after{
            content: '';
            position: absolute;
            left: 0;
            top: -10px;
            width: 100%;
            height: 2px;
            background-color: inherit;
          }
          &:after{
            top: 10px;
          }
        }
      }

        /*設(shè)置選中后的菜單的樣式*/
        /*將menu設(shè)置為fixed,同時(shí)寬高為100%,然后設(shè)置display為flex,否則菜單不會(huì)出現(xiàn)在中間*/
      .menu{
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
        visibility: hidden;    /*將菜單設(shè)置為不可見(jiàn),然后在checkbox選中時(shí)設(shè)置為可見(jiàn)*/
        transition: all .75s ease;
        >div{
          @include set-background($overlay-color);
          width: 200vw;
          height: 200vh;
          overflow: hidden;
          border-radius: 50%;
          display: flex;
          justify-content: center;
          align-items: center;
          text-align: center;
          transform: scale(0);
          transition: all .4s ease;
          >div{
            max-width: 90vw;
            max-height: 90vh;
            opacity: 0;
            transition: all .4s ease;
            >ul>li{
              list-style: none;
              font-size: 2rem;
              padding: .85rem 0;
              text-transform: uppercase;
              transform: skew(-5deg,-5deg) rotate(5deg);/*設(shè)置文字傾斜*/
              a{
                color: inherit;
                text-decoration: none;
                transition: color .4s ease;
              }
            }
          }
        }
      }
    }

    到此這篇關(guān)于HTML+Sass實(shí)現(xiàn)HambergurMenu(漢堡包式菜單)的文章就介紹到這了,更多相關(guān)HTML+Sass實(shí)現(xiàn)HambergurMenu內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

    來(lái)源:腳本之家

    鏈接:https://www.jb51.net/web/729703.html

    申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

    相關(guān)標(biāo)簽
    html

    相關(guān)文章

    熱門(mén)排行

    信息推薦