I made this example easily with CSS display: grid
… but I think it is impossible to reproduce via flex
… is not it?
Link: https://jsfiddle.net/9z43o07g/21/
CSS:
.Message {
display: inline-grid;
grid-template-areas: ". name""date text";
}
.Date {
align-items: center;
display: flex;
grid-area: date;
}
.Name {
grid-area: name;
}
.Text {
grid-area: text;
}
.Date,
.Name,
.Text {
border: 1px solid #f00;
padding: 5px 10px;
}
HTML:
<div class="Message">
<div class="Name">name</div>
<div class="Date">date (vertically centered)</div>
<div class="Text">three<br />line<br />text</div>
</div>
2
Answers
No, it’s not possible to achieve this exact layout with only flexbox, unless you move
.Date
and.Text
elements into another container.However, it’s still not exactly what you have now. So, yeah. You need grid for that.
You have to play with
width:max-content
,justify-content:flex-end
,margin
,wrap
andmin-width
to mimic something very close:example:
Its not because it looks okay, that it is to be used. grid and flex have different purposes and here grid is required 😉