I'm playing with flexbox system in CSS and I can't figure out how to solve my problem.
If I have box with long text, which breaks to two lines, box grows to full width available and I don't want that. If text is on many lines then I want box to grow to width of the longest line. Well, my english is not so good that's why I have images to better show what I want to achieve.
This is what I have now:
And this is what I want to have:
I looked for ready solution in google (and stackoverflow) but without luck. I prepared also JSFiddle for that: http://jsfiddle.net/f98VN/4/
Is it possible to do what I want and if yes then how can I achieve that? If not, what are your suggestions?
Code:
HTML
<div class="flex-parent">
<div class="item1"></div>
<div class="item2">text is here</div>
<div class="item1"></div>
</div>
CSS
.flex-parent {
display: flex;
justify-content: center;
width: 550px; /* it has width of the whole page, in fiddle I changed it to fixed */
align-items: center;
}
.item1 {
background: red;
height: 100px; /* it has constant width */
width: 100px;
}
.item2 { /* it's width is fluid, depends on text inside which is modified by JS */
background: pink;
font-size: 100px;
}