I want to move the page 3 to the next row in the following snippet. But I couldn't find how to do that.
The conditions are
- Pages in a row should be aligned to center. (e.g.
.container { justify-content: center }
) - If wrapping is not necessary (items are small enough), a row should contain 2 pages.
- Page's width is not fixed. (that is, I can't know page width in advance)
I tried pairing by 2 pages, but it broke the requirement 2. Is there a way without js?
How to specify line breaks in a multi-line flexbox layout?
I'm not searching newline after every nth item. If I should find positions for newline and insert on that by js, please let me know that by comment.
Breaking to a new line with inline-block
It also about force line break. I can't find a hint for possibility.
body {
margin: 0;
}
.container {
background: #eee;
display: flex;
flex-flow: row wrap;
justify-content: center;
align-items: center;
}
.page {
width: 35vw;
height: 80vh;
background: #ddd;
border: 1px solid gray;
flex: 0 1 auto;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
}
.long {
width: 70vw;
}
.short {
width: 20vw;
}
<div class="container">
<div class="page short">page 1</div>
<div class="page short">page 2</div>
<div class="page">page 3</div>
<div class="page">page 4</div>
<div class="page long">page 5</div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
<div class="page"></div>
</div>