乱码乱a∨中文字幕,在线免费激情视频,亚洲欧美久久夜夜潮,国产在线网址

  1. <sub id="hjl7n"></sub>

    1. <sub id="hjl7n"></sub>

      <legend id="hjl7n"></legend>

      當前位置:首頁 >  站長 >  編程技術 >  正文

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

       2020-11-30 14:15  來源: 腳本之家   我來投稿 撤稿糾錯

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

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

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

      在VS Code中的文件結構(編譯scss文件用的是easy sass):

      頁面結構(index.html):

      _config.scss:

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

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

      /*混合器,設置背景色及文本顏色*/
      @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設置背景顏色,利用偽類再添加一個背景圖,同時將背景圖的z-index設置為-1(這樣圖片會顯示在里面);
      然后為了讓文字顯示在中間,所以使用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;
              /*使用混合器設置背景色及文本顏色*/
            @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的時候利用css3的scale設置一個縮放效果*/
            &:hover{
              @include set-background(lighten($overlay-color,30%));
              border-color: lighten($overlay-color, 25%);
              transform: scale(.98);
            }
          }
        }
      }

      /*原理:通過checkbox的點中與否來進行樣式的變化(將checkbox透明度設置為0,z-index設置更高),單擊時,會出現(xiàn)菜單,再次點擊,菜單消失*/
      /*給menu-wrap設置fixed,這樣showcase就會占滿整個屏幕;同時將checkbox的opacity設置為0;
      另外注意,需要將checkbox的z-index設置為2,因為hamburger的z-index設置為1,不然會點擊不起作用
      */
      .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;
            /*當checkbox為checked時,設置hamburger里面的div及偽類的旋轉效果*/
          &:checked ~ .hamburger>div{
            transform: rotate(135deg);
              /*偽類實際上旋轉了225度,需要將top設置為0,不然形成的?長短不一致*/
            &:before,&:after{
              transform: rotate(90deg);
              top: 0;
            }
          }

            /*當checkbox選中時再hover,也會設置一個旋轉效果*/
          &: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自身生成中間的橫線,然后設置定位為relative,后面再將其偽類設置為absolute,
            相對于div進行偏移*/
          >div{
            position: relative;
            left: 0;
            top: 0;
            width: 100%;
            height: 2px;
            background-color: #fff;
            transition: all .7s ease;
              /*利用偽類生成第一條和第三條橫線*/
            &:before,
            &:after{
              content: '';
              position: absolute;
              left: 0;
              top: -10px;
              width: 100%;
              height: 2px;
              background-color: inherit;
            }
            &:after{
              top: 10px;
            }
          }
        }

          /*設置選中后的菜單的樣式*/
          /*將menu設置為fixed,同時寬高為100%,然后設置display為flex,否則菜單不會出現(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;    /*將菜單設置為不可見,然后在checkbox選中時設置為可見*/
          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);/*設置文字傾斜*/
                a{
                  color: inherit;
                  text-decoration: none;
                  transition: color .4s ease;
                }
              }
            }
          }
        }
      }

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

      來源:腳本之家

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

      申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點子。點擊此處,共同探討創(chuàng)業(yè)新機遇!

      相關標簽
      html

      相關文章

      熱門排行

      信息推薦