The picture below is an image of the functionality from the site. In the column “Enter a code” the user can enter data using TagsInput. I would like to slightly improve the functionality so that short tags are displayed on one line. I know that you can apply “inline”, but then long tags go beyond the borders of the modal window.
JavaScript
x
16
16
1
.tag {
2
display: flexbox;
3
align-items: center;
4
margin: 5px 0;
5
margin-right: 5px;
6
padding: 0 5px;
7
border: 1px solid black;
8
border-radius: 5px;
9
color: black;
10
overflow: hidden;
11
text-overflow: ellipsis;
12
max-width: fit-content;
13
white-space: nowrap;
14
position: relative;
15
}
16
I have already tried many options, and looked at many answers on stackoverflow, but did not achieve the result. Perhaps you can give me a hint.
Advertisement
Answer
Would be nice if you add a bit more code that this. I’m guessing your tag
class is on the children? What you need is to put the parent container in flex.
JavaScript
1
19
19
1
<body>
2
<div class="tag-container">
3
<div class="tag">100<div class="del">x</div></div>
4
<div class="tag">200<div class="del">x</div></div>
5
<div class="tag">300<div class="del">x</div></div>
6
<div class="tag">400<div class="del">x</div></div>
7
<div class="tag">500<div class="del">x</div></div>
8
<div class="tag">600<div class="del">x</div></div>
9
<div class="tag">700<div class="del">x</div></div>
10
<div class="tag">800<div class="del">x</div></div>
11
<div class="tag">800<div class="del">x</div></div>
12
<div class="tag">1000<div class="del">x</div></div>
13
<input
14
class="input"
15
placeholder="Enter a code"
16
/>
17
</div>
18
</body>
19
JavaScript
1
32
32
1
.tag-container {
2
display: flex;
3
flex-wrap: wrap;
4
justify-content: center;
5
width: 200px; /* Exemple width */
6
border: 1px solid black;
7
}
8
.tag {
9
text-align: center;
10
margin: 5px 0;
11
margin-right: 5px;
12
padding: 0 5px;
13
border: 1px solid black;
14
border-radius: 5px;
15
color: black;
16
}
17
.del {
18
border: none;
19
border-radius: 30%;
20
background-color: transparent;
21
cursor: pointer;
22
color: black;
23
margin-top: -2px;
24
}
25
.input {
26
width: 100%;
27
min-width: 50%;
28
border: none;
29
margin: 5px;
30
border-bottom: 1px solid black;
31
}
32