I am encountering an issue where, upon hovering over the tags, a remove icon is displayed, which increases the space occupied by each tag. As a result, when I hover over the rightmost tag and there is only a small amount of space remaining that cannot accommodate the remove icon, the tag jumps to the bottom or does not get hovered. This behavior is causing a visual inconsistency and disrupting the user experience.
I would appreciate any suggestions or solutions on how to address this problem. Is there a way to prevent the tags from jumping when there is insufficient space for the remove icon upon hovering? Is it possible to incorporate a safe area of remove icon size width on the right side of the design that would only be used when hovering? It's crucial for me to maintain this specific design layout.
.container {
max-width: 500px;
margin: 0 auto;
display: flex;
}
.tags-container {
background-color: #a3b3c6;
padding: 20px;
display:flex;
flex-wrap: wrap;
}
.tag {
display: inline-flex;
transistion: all 1s ease-in-out;
padding: 3px;
background-color: white;
border: 1px solid black;
}
.tag-close {
margin-left: 10px;
height: 16px;
width: 16px;
display:none;
}
.tag:hover {
background-color: red;
}
.tag:hover .tag-close {
display: block;
}
.tags-remove-all {
display: flex;
align-items: center;
padding: 0 10px;
font-size: 32px;
}
<div class="container">
<div class="tags-container">
<div class="tag">
LBL-12334455579
<div class="tag-close">
x
</div>
</div>
<div class="tag">
LBL-12334578
<div class="tag-close">
x
</div>
</div>
<div class="tag">
LBL-1233
<div class="tag-close">
x
</div>
</div>
<div class="tag">
LBL-12334
<div class="tag-close">
x
</div>
</div>
<div class="tag">
LBL-12334
<div class="tag-close">
x
</div>
</div>
<div class="tag">
LBL-12334
<div class="tag-close">
x
</div>
</div>
</div>
<div class="tags-remove-all">
x
</div>
</div>
You can add a negative
margin-right
of size.tag-close
to.tags-container
. But wrap.tags-container
in an additional element withoverflow:hidden;
, so that the displacement is not visible: