Starting with this layout: http://codepen.io/RebelOne/pen/wodbpR
.navbar {
display: flex;
justify-content: space-between;
When I add position: fixed to the navbar, it collapses down and doesn't fill the width of the wrapper. Does anyone know how to fix this? http://codepen.io/RebelOne/pen/bBWyLZ?editors=1100
.navbar {
display: flex;
justify-content: space-between;
background-color: yellow;
position: fixed;
top: 0;
z-index: 99;
}
Display:flex and position:fixed does not go well together.
you can make little changes and make it look like this
Check the following snippet
/* Clear formatting*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* Remove formatting from links*/
a {
color: inherit;
text-decoration: none;
}
/* Set a max width to the content*/
.wrapper {
max-width: 960px;
margin: 0 auto;
background-color: pink;
display: flex;
flex-direction: column;
/*height: 100vh; */
}
.parent {
position: fixed;
top: 0;
left: 0;
margin: auto;
width: 100%;
}
.navbar {
display: flex;
justify-content: space-between;
background-color: yellow;
/* */
}
.logo {
padding: 20px;
}
.menu {
display: flex;
align-items: center;
}
.menu ul {
display: flex;
justify-content: flex-end;
align-items: center;
list-style: none;
background-color: grey;
}
.menu li {
padding: 20px;
margin-left: 20px;
background-color: orange;
color: rgba(255, 0, 0, 0.9);
font-size: 16px;
font-weight: bold;
}
<div class="parent">
<div class="navbar">
<div class="logo">
<picture>
<img src="http://fillmurray.com/50/50" alt="logo">
</picture>
</div>
<div class="menu">
<ul>
<li><a href="#home">Home</a>
</li>
<li><a href="#about">About</a>
</li>
<li><a href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</div>
<div class="wrapper">
<div style="height: 2000px"></div>
</div>
Hope it helps
Add the following css property in navbar class
.navbar {
display: flex;
justify-content: space-between;
background-color: yellow;
position: sticky;
top: 0;
z-index: 100;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With