常春岛资源网 Design By www.syssdc.com
前几天看了国外一个大佬用HTML+CSS实现HamburgerMenu的视频,然后最近在看Sass,所以用Sass来实现一下。
最终效果图如下:
在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设置更高),单击时,会出现菜单,再次点击,菜单消失*/ /*给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,否则菜单不会出现在中间*/ .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; } } } } } }
常春岛资源网 Design By www.syssdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
常春岛资源网 Design By www.syssdc.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年06月01日
2024年06月01日
- PUCK《天蓝色的彼岸》[FLAC/分轨][74.02MB]
- Edward Chan《Blueprint of Memories》[320K/MP3][48.3MB]
- 张敬轩.2007-MY1STCOLLECTION【环球】2CD【WAV+CUE】
- 著名歌手绝美音色经典老歌《超级音效王》DTS-WAV
- 流行靓声-群星《情网HQ》DTS[WAV]
- 群星《经典情歌对唱迟来的爱HQ》DTS[WAV]
- 群星2024《传承(太平洋影音四十五周年纪念专辑)4CD》[FLAC]
- 太平洋唱片中国轻音乐1-10全集[竹锦+影视篇+民歌篇+创作篇等]10CD[APE分轨+CUE]
- 群星《2024第一季度百度排行100首》[FLAC/分轨][2.3G]
- 证声音乐图书馆《聆听·心流·爵士 Flow Jazz》[320K/MP3][77.28MB]
- 证声音乐图书馆《聆听·心流·爵士 Flow Jazz》[FLAC/分轨][132.74MB]
- dnf手游为什么不上线了
- dnf手游韩服怎么重新转职
- 雷婷《婷婷醉歌》发烧版K2HD[正版CD低速原抓WAV+CUE]
- 西卿.1997-西北风(布袋戏精选)【金瓜石】【WAV+CUE】