26

I have the following container of text:

<div class="cardTitles">

<div class="title">
    <div class="titleContent">
        <i class="fa fa-star-o"></i>
        <b>Some long long long title here</b>
        <a href="some href"></a>
    </div>
</div>

... title divs ...

</div>

css:

.cardTitles {
    width: 100%;
    height: 100%;
}

.title
{
    position: relative;

    padding-top: 8px;
    padding-bottom: 8px;
}

I want to make text full width + text-overflow: ellipsis. So when I resize browser all title divs should be full 100% width of the parent cardTitles with cut text to three dots at the end.

I found that this is possible using flex. Here is the possible answer:

.parent-div {
    display: flex;
}

.text-div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;    

    min-width: 0;
}

But this doesn't work for me. Parent container stops resizing when it reach the max length of some child title.


You can find an example here: http://88.198.106.150/tips/cpp/

Try to resize browser and look at title with text: What does it mean that a reference must refer to an object, not a dereferenced NULL pointer. I need to make it overflow ellipsis.

Community
  • 1
  • 1
Max Frai
  • 61,946
  • 78
  • 197
  • 306

4 Answers4

26

Try this out:

.titleContent {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

Here's and updated jsFiddle

KyleMit
  • 30,350
  • 66
  • 462
  • 664
Aakash
  • 1,751
  • 1
  • 14
  • 21
24

No Flex but could work also ... try it.

.element {
  display: table;
  table-layout: fixed;
  width: 100%;
}

.truncate {
  display: table-cell;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

text-overflow ellipsis with 100% width

Amitka
  • 281
  • 2
  • 7
7

The width needs to be added in pixels, percentage wont work along with other three properties as given below:-

.text-ellipsis{
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
Nitesh
  • 1,241
  • 4
  • 16
  • 25
1

#div1 {
   white-space: nowrap; 
   width: 12em; 
   overflow: hidden;
   text-overflow: clip; 
   border: 1px solid #000000;
}

 #div2 {
   white-space: nowrap; 
   width: 12em; 
   overflow: hidden;
   text-overflow: ellipsis; 
   border: 1px solid #000000;
}

The following two divs contains a long text that will not fit in the box. As you can see, the text is clipped.

This div uses "text-overflow:clip":

This is some long text that will not fit in the box

This div uses "text-overflow:ellipsis":

This is some long text that will not fit in the box