I have some text inside a div.
The parent of the div that holds the text has a specific width and display: flex;
I want the width of the container that holds the text to be as wide as its longest textline (in the fiddle this would be the line "WordyWords in").
I know this can be done by: display: inline
, but this only works, when the parent does not have display: flex
anymore.
.width{
width: 150px;
display: flex;
}
.text{
font-size: 20px;
line-height: 20px;
display: inline;
background-color: red;
}
.width2{
width: 150px;
}
.text2{
font-size: 20px;
line-height: 20px;
display: inline;
background-color: red;
}
This is what I have
<div class="width">
<div class="text">Veryvery long WordyWords in here</div>
</div>
<br>
This is kind of what I want, but I want to keep the <span style="background-color: #f2f2f2">display: flex;</span> attribute in the parent
<div class="width2">
<div class="text2">Veryvery long WordyWords in here</div>
</div>
Like shown in the picture, I would like the div .text
to end right after the letter of the longest textline like display: inline
does this. (The red line is where the .text
div should end.) But I want to keep display: flex
property on my parent. Is this even possible with flex set on the parent?