I have a two column layout as in this picture:
Each column contains rows composed of an icon and a label of text.
Each row of the left column must be aligned to the left, as is.
The rows of the right column must be aligned in such a way that the widest row is touching the right edge of the parent container and the other rows align so that their left edges are aligned, as in this picture:
It's hard to wrap my head around that... I am thinking of setting the container's display
to flex
, setting each column's flex
to 1
so that they're of equal width, and then trying to do something with the rows of the right column, but I don't know what. I don't know in advance what the labels of text will be, but I'm sure it's possible they will greatly vary in length and can wrap. Is it even possible to align wrapping label to the right after it has wrapped?
Here's the code that I have so far https://jsfiddle.net/t7qksr3g/1/. It's based on @Kretiss answer, but it doesn't work correctly. When the text in the right column wraps, it doesn't align to the right.
I hope someone can help me. The solution can be completely different from what I've described above, it's not a requirement that the rows are actually inside of vertical containers, I just need to achieve the visual effect.
UPDATE
I think what I want to achieve might be impossible without using JS, because browser's logic for computing container's width with wrapped text inside doesn't work in a way that would allow it CSS Width / Max-Width on Line Wrap?.