Created
August 25, 2021 11:48
-
-
Save Shekey/13e6cca8b7ef80cb840ded6a0eb3a992 to your computer and use it in GitHub Desktop.
Multimenu dropdown with animations (HUGO)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$breakpoints: ( | |
'xs': 576px, | |
'sm': 768px, | |
'md': 1010px, | |
'lg': 1200px, | |
'xl': 1440px, | |
'xxl': 1640px, | |
'xxxl': 1920px | |
); | |
@mixin breakpoint-up($breakpoint) { | |
$value: map-get($breakpoints, $breakpoint); | |
@if $value != null { | |
@media (min-width: $value) { | |
@content; | |
} | |
} | |
@else { | |
@warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. " | |
+ "Please make sure it is defined in `$breakpoints` map."; | |
} | |
} | |
@mixin breakpoint-down($breakpoint) { | |
$value: map-get($breakpoints, $breakpoint); | |
@if $value != null { | |
@media (max-width: ($value - 1)) { | |
@content; | |
} | |
} | |
@else { | |
@warn "Unfortunately, no value could be retrieved from `#{$breakpoint}`. " | |
+ "Please make sure it is defined in `$breakpoints` map."; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$color-black: #000; | |
$color-night: #080808; | |
$color-white: #fff; | |
$color-red: #e11d39; | |
$color-grey: #e6e7ea; | |
$color-grey-light: #f7f7f7; | |
$color-mint: #9dfdb4; | |
.text-night { | |
color: $color-night !important; | |
} | |
.text-white { | |
color: $color-white !important; | |
} | |
.bg-night { | |
background-color: $color-night !important; | |
} | |
.bg-mint { | |
background-color: $color-mint !important; | |
} | |
.bg-grey { | |
background-color: $color-grey !important; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $extraClass := cond .IsHome "" "header--transparent" }} | |
<header class="header {{ $extraClass }}"> | |
<div class="container"> | |
<a href="/" aria-label="Homepage" class="header__logo"> | |
logo here | |
</a> | |
{{- if .Site.Menus.main }} | |
{{ partial "menu" .}} | |
{{ partial "search" .}} | |
{{- end }} | |
</div> | |
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.header { | |
background: rgba($color-black, 0.5); | |
color: $color-white; | |
transition: background 0.5s ease; | |
position: relative; | |
.drop-icon { | |
color: $color-mint; | |
display: inline-block; | |
margin-left: 8px; | |
font-size: 20px; | |
@include breakpoint-down('md') { | |
width: 40px; | |
height: 40px; | |
display: flex; | |
align-items: center; | |
justify-content: flex-end; | |
position: absolute; | |
right: 16px; | |
top: 50%; | |
transform: translateY(-50%); | |
} | |
span { | |
display: none; | |
&:first-of-type { | |
display: inline-block; | |
} | |
} | |
} | |
.container { | |
display: flex; | |
align-items: center; | |
position: relative; | |
flex-wrap: wrap; | |
@include breakpoint-down('md') { | |
padding: 0; | |
} | |
} | |
&__logo { | |
position: relative; | |
z-index: 11; | |
svg { | |
display: inline-block; | |
margin-right: 56px; | |
fill: $color-white; | |
width: 166px; | |
height: 32px; | |
@include breakpoint-down('lg') { | |
margin-right: 20px; | |
} | |
@include breakpoint-down('lg') { | |
width: 126px; | |
height: 24px; | |
} | |
@include breakpoint-down('md') { | |
width: 104px; | |
height: 20px; | |
margin-right: 0; | |
margin-left: var(--container-padding); | |
} | |
} | |
} | |
input[type="checkbox"] { | |
display: none; | |
} | |
input[id="search"]:checked { | |
& + .search { | |
.icon-search-wrap { | |
color: rgba($color-night, 0.8); | |
transition: none; | |
max-height: initial; | |
max-width: initial; | |
background-color: $color-grey; | |
padding: 19px; | |
z-index: 0; | |
opacity: 1; | |
} | |
label:first-of-type { | |
border: none; | |
} | |
.icon-search { | |
transition: max-height 0.3s ease, max-width 0.3s ease, z-index 0s ease, opacity 0.3s ease 0.2s; | |
max-height: 0; | |
max-width: 0; | |
z-index: -100; | |
opacity: 0; | |
padding: 0; | |
} | |
.search__input { | |
top: 58px; | |
transition: opacity 0.2s ease, z-index 0s ease, top 0.2s ease, width 1s ease 0.4s; | |
opacity: 1; | |
width: 100%; | |
z-index: 100; | |
input { | |
transition: width 0.5s ease; | |
&::placeholder { | |
opacity: 1; | |
transition: opacity 0.3s ease 0.8s; | |
} | |
} | |
@include breakpoint-up('md') { | |
top: 84px; | |
width: 100%; | |
width: calc(100% - 2 * var(--container-padding)); | |
} | |
} | |
} | |
} | |
.menu-text { | |
@include breakpoint-up('md') { | |
margin: 0 12px; | |
} | |
@include breakpoint-up('xxl') { | |
margin: 0 20px; | |
} | |
} | |
ul { | |
list-style: none; | |
} | |
&--transparent { | |
background: transparent; | |
color: $color-night; | |
.drop-icon { | |
color: $color-night; | |
} | |
svg { | |
fill: $color-night; | |
} | |
} | |
} | |
input[id="burger"] { | |
display: none; | |
&:checked + .body-overflow { | |
@include breakpoint-down('xxl') { | |
overflow: hidden; | |
height: 100vh; | |
} | |
.header { | |
@include breakpoint-down('xxl') { | |
background: $color-white; | |
color: $color-night; | |
transition: background 0.5s ease; | |
} | |
&__logo svg { | |
@include breakpoint-down('xxl') { | |
fill: $color-night; | |
} | |
} | |
.search__input { | |
@include breakpoint-down('xxl') { | |
opacity: 0 !important; | |
transition: width 0.4s ease, top 0.2s ease 0.4s, opacity 0.3s ease 0.2s, z-index 0s ease 0.6s; | |
z-index: -1 !important; | |
} | |
} | |
.search { | |
@include breakpoint-down('xxl') { | |
flex: 1; | |
padding: 28px 0; | |
} | |
@include breakpoint-down('md') { | |
padding: 0; | |
} | |
label:first-of-type { | |
@include breakpoint-down('xxl') { | |
border: none; | |
} | |
} | |
} | |
.icon-search-wrap { | |
@include breakpoint-down('xxl') { | |
display: none; | |
} | |
} | |
.container { | |
.menu__button { | |
justify-content: center; | |
border: 1px solid $color-night; | |
@include breakpoint-down('md') { | |
border: none; | |
background: $color-grey; | |
transition: background 0.5s ease-in; | |
} | |
span { | |
@include breakpoint-down('xxl') { | |
display: none; | |
} | |
&:last-of-type { | |
@include breakpoint-down('xxl') { | |
transition: max-height 0.3s ease, height 0.3s ease 0s, z-index 0s ease, opacity 0.3s ease 0.2s; | |
height: auto; | |
max-height: initial; | |
z-index: 10; | |
opacity: 1; | |
width: 24px; | |
display: flex; | |
justify-content: center; | |
} | |
@include breakpoint-down('md') { | |
justify-content: center; | |
} | |
} | |
} | |
} | |
.drop-icon { | |
@include breakpoint-down('xxl') { | |
color: $color-night; | |
} | |
} | |
.menu { | |
transition: max-height 0.3s ease, height 0.3s ease 0s, z-index 0s ease, background 0.5s ease, opacity 0.3s ease 0.2s; | |
height: calc(100vh - 56px); | |
max-height: 100vh; | |
z-index: 10; | |
opacity: 1; | |
padding-top: 32px; | |
box-shadow: inset 1px 3px 16px 0 rgba($color-night, 0.15); | |
@include breakpoint-up('md') { | |
display: block; | |
overflow-y: auto; | |
flex-basis: calc(100% + 2 * var(--container-padding)); | |
order: 2; | |
margin: 0 calc(-1 * var(--container-padding)); | |
} | |
@include breakpoint-up('xxl') { | |
flex: 1; | |
opacity: 1; | |
order: initial; | |
max-height: initial; | |
height: initial; | |
z-index: initial; | |
display: flex; | |
overflow: initial; | |
box-shadow: none; | |
margin: 0; | |
padding: 0; | |
} | |
@include breakpoint-down('xxl') { | |
background: $color-grey-light; | |
} | |
} | |
.menu__sublist { | |
margin: 0; | |
width: calc(100% + 2 * var(--container-padding)); | |
max-width: calc(100% + 2 * var(--container-padding)); | |
background: transparent; | |
&::after { | |
@include breakpoint-down('xxl') { | |
content: none; | |
} | |
} | |
a:hover { | |
@include breakpoint-down('xxl') { | |
background-color: $color-grey; | |
} | |
} | |
} | |
.menu__list { | |
@include breakpoint-down('xxl') { | |
display: block; | |
} | |
} | |
.menu__item { | |
@include breakpoint-down('xxl') { | |
margin: 0; | |
a:hover { | |
background-color: $color-grey; | |
} | |
} | |
&.big { | |
@include breakpoint-down('xxl') { | |
font-size: 20px; | |
line-height: 32px; | |
} | |
} | |
.menu__link { | |
@include breakpoint-down('xxl') { | |
padding: 16px var(--container-padding); | |
} | |
@include breakpoint-down('md') { | |
padding: 16px; | |
} | |
} | |
} | |
.menu__list-right { | |
@include breakpoint-down('xxl') { | |
z-index: 1; | |
max-height: initial; | |
height: initial; | |
overflow: hidden; | |
transition: opacity 0.3s, max-height 0.3s ease 0.3s, height 0.3s ease 0.3s, z-index 0s ease 0.3s; | |
opacity: 1; | |
overflow-y: auto; | |
display: block; | |
position: relative; | |
} | |
@include breakpoint-up('xxl') { | |
display: flex; | |
flex: 1; | |
justify-content: flex-end; | |
border-top: none; | |
} | |
&::before { | |
@include breakpoint-down('xxl') { | |
content: ''; | |
position: absolute; | |
left: var(--container-padding); | |
width: calc(100% - 2 * var(--container-padding)); | |
height: 1px; | |
top: 0; | |
border-top: 1px solid rgba($color-night, 0.25); | |
} | |
} | |
ul { | |
@include breakpoint-down('xxl') { | |
margin: 0; | |
display: block; | |
} | |
} | |
} | |
.menu__dropdown input[type="checkbox"] { | |
@include breakpoint-down('xxl') { | |
~ .menu__sublist { | |
display: none; | |
} | |
} | |
&:checked ~ .menu__link { | |
@include breakpoint-down('xxl') { | |
color: $color-night; | |
background-color: $color-grey; | |
} | |
.drop-icon span { | |
@include breakpoint-down('xxl') { | |
display: inline-block; | |
&:first-of-type { | |
display: none; | |
} | |
} | |
} | |
& ~ .menu__sublist { | |
@include breakpoint-down('xxl') { | |
border: none; | |
visibility: visible; | |
transition: none; | |
opacity: 1; | |
display: block; | |
position: relative; | |
padding: 0; | |
} | |
@include breakpoint-down('md') { | |
background-color: $color-grey-light; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="checkbox" id="search"> | |
<div class="search"> | |
<label role="button" aria-label="Išči" for="search"><i class="icon-search icon-search-wrap"></i></label> | |
<label role="button" aria-label="Zapri iskanje" for="search"><i class="icon-close icon-search-wrap"></i></label> | |
<label role="button" class="menu__button" aria-label="Meni" for="burger" aria-haspopup="true" aria-expanded="false" tabindex="0"> | |
<span tabindex="-1"><i class="icon-hamburger"></i></span> | |
<span tabindex="-1"><i class="icon-close"></i></span> | |
</label> | |
<div class="search__input"> | |
<input type="text" aria-label="Iskalno polje za članke" placeholder="Poiščite po vsebini"> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.search { | |
display: flex; | |
flex: 1; | |
justify-content: flex-end; | |
@include breakpoint-up('md') { | |
flex: initial; | |
} | |
label { | |
&:not(.menu__button) { | |
display: flex; | |
align-items: center; | |
position: relative; | |
&:focus { | |
outline: 0; | |
} | |
&:first-of-type { | |
@include breakpoint-up('md') { | |
border: 1px solid $color-white; | |
} | |
} | |
} | |
&[for="search"] { | |
.icon-close { | |
transition: max-height 0.3s ease, max-width 0.3s ease, z-index 0s ease, opacity 0.4s ease 0.2s; | |
max-height: 0; | |
max-width: 0; | |
z-index: -100; | |
opacity: 0; | |
display: inline-block; | |
margin: 0; | |
font-size: 18px; | |
overflow: hidden; | |
} | |
.icon-search { | |
transition: max-height 0.3s ease, max-width 0.3s ease, z-index 0s ease, opacity 0.3s ease 0.2s; | |
max-height: initial; | |
max-width: initial; | |
z-index: 0; | |
opacity: 1; | |
display: inline-block; | |
font-size: 18px; | |
padding: 18px; | |
overflow: hidden; | |
@include breakpoint-down('md') { | |
margin: 0 20px; | |
padding: 0; | |
} | |
} | |
} | |
} | |
&__input { | |
position: absolute; | |
right: var(--container-padding); | |
top: 24px; | |
opacity: 0; | |
transition: width 0.4s ease, top 0.2s ease 0.4s, opacity 0.3s ease 0.2s, z-index 0s ease 0.6s; | |
width: 57px; | |
z-index: -1; | |
@include breakpoint-down('md') { | |
top: 44px; | |
right: 0; | |
} | |
&::before { | |
content: "\e901"; | |
font-family: 'icomoon', sans-serif; | |
top: 16px; | |
right: 16px; | |
position: absolute; | |
color: rgba($color-night, 0.6); | |
font-size: 18px; | |
z-index: 10; | |
@include breakpoint-up('md') { | |
top: 20px; | |
right: 20px; | |
} | |
} | |
input { | |
transition: width 0.5s ease; | |
width: 100%; | |
padding: 16px 0; | |
text-indent: 16px; | |
position: relative; | |
border: none; | |
border-bottom: 1px solid $color-night; | |
@include breakpoint-up('md') { | |
text-indent: 32px; | |
padding: 20px 0; | |
} | |
&::placeholder { | |
opacity: 0; | |
transition: opacity 0.1s ease 0.1s; | |
} | |
&:focus { | |
outline: 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment