I have a div with a fixed width. It has two children:
- First one containing text,
- The second one is something like a "badge" (just a div with fixed width and height).
So I want to achieve something like this:-
I want the second child to be located right next to the text of the first child
I've tried to solve this issue by adding display: flex
to the parent, but the problem is that the first child takes width more than its contents (example in the snippet below)
I've tried to add flex-basis: 0
to the first child, but then each word starts with a new line, even if there is enough place to display the whole text in one line.
Maybe there is another solution? I've tried to solve the issue using absolute positioned child but failed also.
.parent {
width: 150px;
background: lightblue;
display: flex;
align-items: center;
}
.first-child {
outline: 1px solid red;
}
.first-child span {
outline: 1px solid white;
}
.second-child {
outline: 1px solid blue;
width: 20px;
height: 10px;
flex-shrink: 0;
}
<div class="parent">
<div class="first-child">
<span>Loooooooong teeeeeext</span>
</div>
<div class="second-child">
</div>
</div>
<br /><br />
<div class="parent">
<div class="first-child">
<span>Short text</span>
</div>
<div class="second-child">
</div>
</div>