I want to create a collapsing menu with flexbox, but when I click the hamburger icon the LOGO and the hamburger icons get moved to the top which is annoying,
I think this is because of flexbox is trying to vertically re-center elements when the div.menu-items appears!
Any solution? here is the full snippet:
html {
line-height: 1.15;
-webkit-text-size-adjust: 100%;
box-sizing: border-box;
font-size: 62.5%;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
margin: 0;
line-height: 1.6;
font-size: 1.6em;
font-family: "Roboto", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
margin: 0;
padding: 0;
color: #182c56;
color: #4a4a4a;
}
img{
vertical-align: middle;
border-style: none;
}
.menu{
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
width: 100%;
margin: 0 auto;
padding: .8rem 1.6rem;
min-height: 10rem;
background: #FFF;
background: #efefef;
}
.brand, .menu-icon{
background: magenta;
}
.brand{
display: inline-block;
font-size: 1.0625rem;
white-space: nowrap;
line-height: inherit;
}
.brand img{
max-height: 4rem;
padding-right: 1rem;
}
.menu-checkbox{
display: none;
}
.menu-icon{
line-height: 1;
cursor: pointer;
display: inline-block;
padding: 1rem;
user-select: none;
background: magenta;
margin-bottom: 0;
}
.menu-items {
flex-basis: 100%;
display: flex;
flex-direction: column;
text-align: center;
display: none;
}
.menu-right a{
flex-wrap: wrap;
justify-content: center;
}
.menu-checkbox:checked ~ .menu-items
{
display: flex;
}
<div class="menu sticky">
<a class="brand">
<img src="https://www.freecodecamp.org/news/content/images/2019/11/fcc_primary_large_24X210.svg" alt="">
</a>
<input class="menu-checkbox" type="checkbox" id="menu-collapse" />
<label class="menu-icon" for="menu-collapse">
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd"><path d="M24 18v1h-24v-1h24zm0-6v1h-24v-1h24zm0-6v1h-24v-1h24z" fill="#1040e2"/><path d="M24 19h-24v-1h24v1zm0-6h-24v-1h24v1zm0-6h-24v-1h24v1z"/></svg>
</label>
<div class="menu-items">
<a href="#work">Our Work</a>
<a href="#about">About</a>
<a href="#careers">Careers</a>
<a href="#contact">Contact</a>
</div>
</div>