The problem of ellipsis style of indefinite length text with border


<div class="parent">
    <div class="div1"></div>
    <div class="div2">
        <span class="tag"></span>
    </div>
</div>

.parent {
    width: 200px;
    display: flex;
    border: 1px solid pink;
}
.tag {
    border: 1px solid skyblue;
}

ask CSS to achieve the effect shown in the picture

ordinary ellipsis will definitely fail. If omitted on div2, the right side of blue border will also be truncated and will have no effect on tag.

Css
Jan.25,2022

display:block;overflow: hidden;text-overflow: ellipsis; white-space: nowrap;

solved the omission failure of
on tag mainly by setting min-width, on the parent element, which is a common problem in the combination of flex and ellipsis.

.parent {
    width: 200px;
    display: flex;
    border: 1px solid pink;
}
.div2 {
    flex: 1;
    min-width: 0;
}
.tag {
    border: 1px solid skyblue;
    display: inline-block;
    max-width: 100%;
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap;
}


set the width of the parent element and set overflow: hidden;text-overflow: ellipsis;white-space: nowrap;

Menu