Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text-overflow: ellipsis not working in a div containing a div in Chrome

Tags:

html

css

I want to have all text be ending with '...' but it only works for the inner div:

div {
  border: solid 2px blue;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 40px;
}
<div>Test test test test test test
  <div>asdasdasdasdasd</div>
</div>

http://jsfiddle.net/JU8Up/

is there any Solution so that also the text contained in the outer div gets the '...' ?

edit: seems like its a chrome problem, but still the fix in the answer below works

like image 265
Nick Russler Avatar asked Sep 26 '12 12:09

Nick Russler


People also ask

Why does text-overflow ellipsis not working?

If your text-overflow is not working you must ensure display, overflow and white-space CSS properties are set to proper values. Ellipsis works in the same way on all types of elements. But you need to use it with caution on Flex, CSS Grid or on a Table.

How do I force text-overflow ellipsis?

Inline overflow occurs when the text in a line overflows the available width without a breaking opportunity. To force overflow to occur and ellipses to be applied, the author must apply the nowrap value to the white-space property on the element, or wrap the content in a <NOBR> tag.

How do I fix text-overflow in CSS?

A text-overflow property in CSS is used to specify that some text has overflown and hidden from view. The white-space property must be set to nowrap and the overflow property must be set to hidden. The overflowing content can be clipped, display an ellipsis ('…'), or display a custom string.


1 Answers

It works by adding float: left; to the div CSS, but without any further context I can't comment on what side-effects that may have in your implementation.

Example here.

like image 167
chrisfrancis27 Avatar answered Oct 09 '22 07:10

chrisfrancis27