I have a label where I need to add an ellipsis to, but I can't get it to work:
<label id="div2">This is some long text that will not fit in the box</label>
label#div2 {
white-space: nowrap;
width: 30px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000000;
}
JSFiddle
To clip at the transition between characters you can specify text-overflow as an empty string, if that is supported in your target browsers: text-overflow: ''; . This keyword value will display an ellipsis ( '…' , U+2026 HORIZONTAL ELLIPSIS ) to represent clipped text.
text-overflow: ellipsis only works when the following is true: Parent element is not set to display: inline (span's default,) You must use display: block or display: inline-block. The element's width must be constrained in px (pixels) – it doesn't work with values specified using % (percent.)
The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (...), or display a custom string.
To hide overflow in an element, the element needs to be block-level. But you probably don't want an inline label to be block-level because that could cause other issues. So just make it inline-block
:
label#cats {
white-space: nowrap;
width: 30px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid #000000;
display: inline-block;
}
jsFiddle: http://jsfiddle.net/rdg221bx/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With