I have a top nav bar which has two children: one that contains the icon and another one that contains the nav options. Since the nav options are variable and longer than the viewport, I'd like to enable that to be horizontally scrollable.
Here is the JSFiddle that shows it: https://jsfiddle.net/zhbx2ert/3/
HTML:
<div class="parent">
<div class="iconspace">
¯\_(ツ)_/¯
</div>
<div class="rest">
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
<li>I</li>
<li>J</li>
<li>K</li>
<li>L</li>
</ul>
</div>
</div>
CSS
body {
background: teal;
}
.parent {
width: 100%;
height: 80px;
background: mistyrose;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 0 2em;
border-radius: 50px;
position: relative;
}
.iconspace {
width: 100px;
background: slategray;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.rest {
width: calc(100% - 100px);
height: 100%;
background: papayawhip;
overflow-x: auto;
position: relative;
}
ul {
display: flex;
justify-content: space-evenly;
align-items: center;
list-style-type: none;
height: 100%;
width: 100%;
margin: 0;
}
li {
border: 1px solid brown;
border-radius: 50%;
min-height: 32px;
min-width: 32px;
display: inline-flex;
justify-content: center;
align-items: center;
margin: 0 1em;
color: crimson;
}
The problem you'll notice in the demo is that the first few items of the list are never visible. I am not sure why the list doesn't start at the beginning of the parent but instead starts at the beginning of the grandparent.
Any ideas are much appreciated!