I am creating a navbar that will horizontally scroll when it is larger than its parent container.
It has a bottom border on the navbar with a different border color for the active link. Using a negative margin to overlap them works fine but when adding overflow-x: auto;
the active color disappears.
Here is a codepen to demonstrate: https://codepen.io/scottknight/pen/aboxYZY
(uncomment the overflow-x and the active border appears)
<div class="container">
<div class="navbar">
<a href="#" class="navlink">Link One</a>
<a href="#" class="navlink active">Link Two</a>
<a href="#" class="navlink">Link Three</a>
<a href="#" class="navlink">Link Four</a>
<a href="#" class="navlink">Link Five</a>
<a href="#" class="navlink">Link Six</a>
<a href="#" class="navlink">Link Seven</a>
<a href="#" class="navlink">Link Eight</a>
<a href="#" class="navlink">Link Nine</a>
<a href="#" class="navlink">Link Ten</a>
</div>
</div>
.container {
width: 800px;
}
.navbar {
display: flex;
/* overflow-x: auto; */
border-bottom: solid;
border-bottom-width: 5px;
border-color: gray;
}
.navlink {
padding: 20px;
flex: none;
margin-bottom: -5px;
}
.navlink.active {
border-bottom: solid;
border-bottom-width: 5px;
border-color: red;
}