I have a list whose width is set in pixels. It has two list items: One whose content is shorter than the list, and one whose content extends past the width.
How can I make it so that the list items each have a width equal to the larger of the list width and the list item content width (so that the second item in this example contains its content)?
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
ul {
width: 400px;
overflow-x: scroll;
outline: 1px dashed red;
}
li {
max-width: none;
min-width: 100%;
padding: 0.5rem 1rem;
white-space: nowrap;
background-color: skyblue;
outline: 1px dashed blue;
}
<ul>
<li>test</li>
<li>test test test test test test test test test test test test test test test test test test test test</li>
</ul>
2
Answers
You can use
display: inline-block
instead ofdisplay: block
so the width of the list is wrap to the contentSample below:
Reference: https://developer.mozilla.org/en-US/docs/Web/CSS/display
make the container
display: grid
and both items will extend to the largest one