I have some items that I'd like to arrange in flex-box, so that they will wrap on smaller screens. flex-wrap:wrap;
can do this.
When they are "unwrapped" (i.e. a wide screen), I'd like there to be a vertical line between the content elements. When the screen/container narrows, I'd like them to wrap to the next line and not have a border.
I want the entire thing to be in the centre of the page. It is not required that all the content elements have the same width.
Something like this:
I have seen Smart borders between flex items – the dumb way, but this doesn't work when the flex-box container is "floating" in the page, as it relies on a hidden -1px margin to hide the spare border, which means the items must stretch all the way to the left margin in order to hide their margins. For centred boxes, this is not always true.
/* Based on https://codepen.io/thatemil/pen/MrrJyZ
* used by
* https://thatemil.com/blog/2018/01/08/direction-independent-borders-this-is-stupid/
*/
.container {
display: flex;
flex-wrap: wrap;
overflow: hidden;
justify-content: center;
}
.item {
border-left: 1px solid red;
margin-left: -1px;
padding: 5px;
}
Short (unwrapped):
<div class="container">
<div class="item" style="background-color:pink;">foobar</div>
<div class="item" style="background-color:grey;">quux</div>
</div>
Long (wrapping):
<div class="container">
<div class="item" style="background-color:pink;">foobar foobar foobar foobar foobar foobar</div>
<div class="item" style="background-color:grey;">quux quux quux quux quux quux quux</div>
</div>