I have a flex container that the position
needs to be absolute
. I also wish the size of the container is determined by its children.
But when I assigned position: absolute
and display: flex
for the parent, and assigned flex: 1 0 80px
to its children. It seems the width of the container is not changed accordingly.
How do I fix this?
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
position: absolute;
display: flex;
top: 40px;
left: 40px;
border: solid 1px rgba(0, 0, 0, 0.2);
}
ul li {
flex: 1 0 80px;
text-align: center;
}
ul li:not(:first-child) {
border-left: inherit;
}
<ul>
<li>layout</li>
<li>text</li>
<li>media</li>
<li>form</li>
<li>button</li>
<li>somelongcontents</li>
</ul>