I'm trying to build a responsive header component for a site. The header has position: fixed
so that it doesn't scroll, but contains a horizontally scrolling list of options.
I used this tutorial to build the horizontally-scrolling internals so that the list of header items could be scrolled but no scrollbar would be displayed. Check out the code below, and see it working in this fiddle.
HTML
<body>
<main class="fixed-container">
<div class="scroll-container">
<ul class="scroll-list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</main>
</body>
CSS
.fixed-container {
position: fixed;
height: 75px;
overflow: hidden;
right: 0;
left: 0;
border-bottom: 2px solid black;
}
.scroll-container {
height: 100%;
overflow-x: auto;
overflow-y: hidden;
box-sizing: content-box;
padding-bottom: 17px;
}
.scroll-list {
list-style: none;
display: flex;
height: 100%;
width: 1000px;
margin: 0;
padding-left: 0;
}
.scroll-list li {
flex: 1 0;
text-align: center;
padding-top: 2em;
border-bottom: 2px solid red;
margin-left: 5px;
margin-right: 5px;
}
<div class="scroll-container">
, with height: 100%
, fills the height of the <main class="fixed-container">
as expected. However the <ul>
within the div, which also has height: 100%
, does not fill the height of its parent. There is space between the red borders at the bottom of the <li>
s within and the black border at the bottom of the <main class="fixed-container">
.
Note that if overflow-x: auto
and overflow-y: hidden
are removed from <div class="scroll-container">
, or if right: 0
is removed from <main class="fixed-container">
then the heights behave as expected and the red borders are flush with the top of the black border.
How can I get the <ul>
to fit the height of its parent so that the red borders sit directly on top of the black border?