HTML+Sass实现HambergurMenu(汉堡包式菜单)

时间:2021-05-08

前几天看了国外一个大佬用HTML+CSS实现HamburgerMenu的视频,然后最近在看Sass,所以用Sass来实现一下。

最终效果图如下:

在VS Code中的文件结构(编译scss文件用的是easy sass):

页面结构(index.html):

_config.scss:

$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{ 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{ @include set-background(lighten($overlay-color,30%)); border-color: lighten($overlay-color, 25%); transform: scale(.98); } } }}.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; &:checked ~ .hamburger>div{ transform: rotate(135deg); &:before,&:after{ transform: rotate(90deg); top: 0; } } &: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{ 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{ position: fixed; left: 0; top: 0; width: 100%; height: 100%; overflow: hidden; display: flex; justify-content: center; align-items: center; visibility: hidden; 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实现HambergurMenu(汉堡包式菜单)的文章就介绍到这了,更多相关HTML+Sass实现HambergurMenu内容请搜索以前的文章或继续浏览下面的相关文章,希望大家以后多多支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章