I'm not sure if it's possible with flexbox, but I am looking to create a list with two items displayed side by side where the width of each item adjusts based on the content. Here is an example:
<div class="items">
<div class="item">Item 1 with text</div>
<div class="item">Item 2 with more text</div>
<div class="item">Item 3 with some text</div>
<div class="item">Item 4 without text</div>
<div class="item">Item 5 lorem</div>
<div class="item">Item 6 ipsum</div>
<div class="item">Item 7 with lorem</div>
<div class="item">Item 8 with ipsum</div>
</div>
.items {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}
.item {
align-self: flex-end;
box-sizing: border-box;
background: #e0ddd5;
color: #171e42;
padding: 10px;
}
.item:nth-child(even) {
background-color: darkgrey;
}
Is there a way to ensure that always two items are displayed side by side regardless of how many list items are present? There are no outer containers limiting the width, and I prefer not to use float. Would using grid template columns offer a flexible solution?
The desired end result should look like this (but aligned to the right):