Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On css: if text line is break show dots

Tags:

css

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>
like image 386
OnengLar Avatar asked Jul 25 '13 20:07

OnengLar


People also ask

How do you break a text line in CSS?

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).

How do you stop a line from breaking text in CSS?

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).


2 Answers

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/

like image 194
verbanicm Avatar answered Sep 24 '22 10:09

verbanicm


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; } 
like image 45
Firas Medini Avatar answered Sep 23 '22 10:09

Firas Medini