I’m trying to replicate the behaviour you have for a Chrome tab on windows.
The minimum width of the tab is set to the width of the close button and it will clip any text as the tab shrinks ensuring there is always a gap between any visible text and the close button.
Here is where I’ve gotten to:
https://jsfiddle.net/f7tc34q6/9/
#parent {
background: grey;
display: flex;
height: 50px;
}
#item {
align-items: center;
display: flex;
background: blue;
min-width: fit-contents;
width: 40px;
}
span {
display: inline;
min-width: 0;
overflow: hidden;
word-break: nowrap;
padding-right: 5px;
}
button {
display: block;
width: 20px;
height: 20px;
}
<div id="parent">
<div id="item">
<span>Text</span>
<button></button>
</div>
</div>
This isn’t even close. The min-width: min-content
doesn’t behave, the text doesn’t clip and there is no gap between the text and close button.
2
Answers
Firstly, I was adjusting your code and noticed that you have a few invalid values?
For example,
nowrap
seems to be invalid for propertyword-break
. Instead, you could usewhite-space: nowrap;
. The functionality you are going for should be the same.Next, addressing your main question, Chrome’s tabs seem to not really have a "gap," per se, but rather a fade-out/hiding effect. To incorporate something like this, you could use a CSS
mask-image
(Note that this might not work on older browser versions).Here’s a working snippet (I tweaked some things so I could see better):
Update your code like below