I am placing some spans inside mat-toolbar which by default has display flex. Now I want some of the items on the extreme right. I use margin-left: auto
for these elements. The problem is that these elements are stretched in order to fill the entire flexbox. What I want is some elements, followed by empty space, followed by the elements with margin-left: auto
having their width as fit-content.
This is my code:
HTML:
<div>
<span>Flex item</span>
<span class="right">Flex item</span>
<span class="right">Flex item</span>
</div>
CSS:
div {
display: flex;
border: 1px dotted black;
}
.right { margin-left: auto; }
span {
background-color: #E0E0E0;
border: solid 1px black;
padding: 10px
}