I seen before this solution but i not remember where exactly... without JS
maybe it's work when line is break. But what a css property is?
Question is: how to show for user: dots, if text longer than 150px
DEMO
div { font-family: Arial; background: #99DA5E; margin: 5px 0; padding: 1%; width: 150px; overflow: hidden; height: 17px; color: #252525; }
<div>apple</div> <div>jack fruit</div> <div>super puper long title for fruit</div> <div>watermelon</div>
A line-break can be added in HTML, using only CSS, by employing the pseudo-class ::after or ::before . In the stylesheet, we use these pseudo-classes, with the HTML class or id, before or after the place where we want to insert a line-break. In myClass::after : Set the content property to "\a" (the new-line character).
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
Are you talking about an ellipsis? Add this to your CSS
text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
Fiddle: http://jsfiddle.net/5UPRU/7/
In order for text-overflow: ellipsis
to work you must also specify a width
(or a max-width
), white-space: nowrap
and overflow: hidden
The element must be a block so make sure to use display: block
or display: inline-block
on inline elements.
div { width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
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