2

I want that a label in HTML has a max width of like 100px and if this label has a text that is longer than 100px it gets cut off. A perfect result would be a cut and some points ".." at the end.

I have:

<label> This is some long text on my website </label>

Desired result would be something like:

This is some lo..

Is this possible with CSS alone? For a start it would be okay if it only gets cut at the end. Thank you in advance!

I tried to set the width to 100px in CSS but that only changes the size of e.g. the backgroundcolor of the label and not the text.

Jonas
  • 2,139
  • 17
  • 38

1 Answers1

11

label {
  width : 130px;
  overflow:hidden;
  display:inline-block;
  text-overflow: ellipsis;
  white-space: nowrap;
}
<label> This is some long text on my website </label>
Kudos
  • 1,084
  • 8
  • 21