4

In html, I have a button that contains two icons and a span with text. In css, I use flex and overflow properties in order to truncate the text if it is too long. The code works fine for all browsers, except IE. Here is the example on jsfiddle: https://jsfiddle.net/fu6kfhw9/1/

HTML

<button>
  <div class="container">
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
    <span>TestTestTestTest</span>
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
  </div>
</button>

CSS

body, button {
  max-width: 100px;
}

.container {
  width: 100%;
  display: flex;

  span {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

Thanks in advance, Mark

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Mark
  • 43
  • 3

3 Answers3

3

You can remove the flex property on the span.

fiddle

body,
button {
  max-width: 100px;
}

.container {
  width: 100%;
  display: flex;
}

span {
  overflow: hidden;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<button>
  <div class="container">
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
    <span>TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest</span>
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
  </div>
</button>
sol
  • 22,311
  • 6
  • 42
  • 59
1

there are different CSS flex' for the browsers. This one should work for IE: HTML

 <button>
  <div class="container">
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
    <span>TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest</span>
    <i class="fa fa-file-pdf-o" aria-hidden="true"></i>
  </div>
</button>

CSS:

    body, button {
  max-width: 100px;
}

.container {
  width: 100%;
  display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;      /* TWEENER - IE 10 */
  display: -webkit-flex;     /* NEW - Chrome */
  display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */

  span {
    flex: 1;
    -ms-flex: 1 0 auto;
    overflow: hidden;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

Working jsfiddle: https://jsfiddle.net/fu6kfhw9/7/

You might be able to remove all the different flexes though and just keep the normal one and the IE one.

Mik3NL
  • 397
  • 2
  • 21
0

If you want to keep the flexbox you can set a fixed width for the span:

body, button {
  max-width: 100px;
}

.container {
  width: 100%;
  display: flex;
  display: -ms-flexbox; /* ie Flex */

  span {
    flex: 1;
    -ms-flex: 1 0 auto; /* ie Flex */
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 50px; /* fix width of span */
  }
}

https://jsfiddle.net/fu6kfhw9/10/

tymothytym
  • 1,571
  • 3
  • 16
  • 25