I have a fixed width menu, with flex items.
'New' items in the menu have a notification style label after the item text. When the text is short, the label positions immediately after the text (see 'News' item in the snippet).
If the text is long it forces the label to the right of the menu leaving a white-space gap between the text and the label (see 'Looooonggggg Newwwwws & Blogggggs' item in snippet).
I have tried, justify-content: flex-start
, and flex: 0 1 auto
- they do nothing. If I use flex: 0 1 0
the item text breaks to it's longest word - which is not what I am looking for.
Does anyone know how I always position the labels immediately after the item text?
The position I am trying to achieve:
body {
background: blue;
}
.menu {
background: white;
width: 290px;
}
.item {
padding: 1rem;
display: block;
align-items: center;
display: flex;
}
.label {
margin-left: .5rem;
width: .5rem;
height: .5rem;
background: red;
border-radius: 50%;
}
.shrunk div {
flex: 0 1 0;
}
<div class="menu">
<a class="item new" href=""><div>News</div><span class="label"></span></a>
<a class="item new" href=""><div>Looooonggggg Newwwwws & Blogggggs</div><span class="label"></span></a>
<a class="item" href=""><div>Blogs</div></a>
<a class="item new shrunk" href=""><div>If I set flex shrink and basis to 0 this happens</div><span class="label"></span></a>
</div>