I’m struggling with a simple navbar. I can’t make a responsive fixed to the top navbar with logo and navlinks in both sides.
I got rid of everthing Bootstrap related in the code I’m sharing here can you please have a look and save me?
I’m looking for a bootstrap solution, to make things responsive. thank you.
.nav-bar {
display: flex;
justify-content: space-between;
position: fixed;
align-items: center;
}
.header-top {
height: 100px;
display: flex;
justify-content: space-between;
padding: 15px 30px 0 10px;
}
.nav-links {
display: flex;
right: 20px;
}
.header-nav-blocks {
height: 50px;
margin-left: 40px;
display: flex;
justify-content: center;
align-items: center;
}
.header-nav-button {
display: flex;
flex-direction: column;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<header>
<div class="header-top">
<nav class="nav-bar">
<img src="https://via.placeholder.com/50" alt="logo oc" />
<ul class="nav-links">
<li class="header-nav-blocks">
<a href="#A" class="navlinks">A</a>
</li>
<li class="header-nav-blocks">
<a href="#B" class="navlinks">B</a>
</li>
<li class="header-nav-blocks">
<a href="#C" class="navlinks">C</a>
</li>
<li class="header-nav-blocks">
<a href="#D" class="navlinks">D</a>
</li>
<li class="header-nav-button">
<a href="" class="button-link">Blog</a>
</li>
</ul>
</nav>
</div>
</header>
2
Answers
I just added
position:absolute
to.nav-links
.I think you are trying to achieve this:
If I am wrong, please let me know in comment section.
All you needed to do was make your navbar full width. When you make an element a flex container it collapses by default to the width of its children.