Button text is not displayed when using flex display (only in IE)

In html, I have a button containing two icons and an interval with text. In css, I use the flex and overflow properties to truncate the text if it is too long. The code works fine for all browsers except IE. Here is a jsfiddle example: 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

+4
source share
3 answers

You can remove the property flexon 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>
Run codeHide result
+3
source

There are different CSS flex for browsers. This 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;
  }
}

Jsfiddle work: https://jsfiddle.net/fu6kfhw9/7/

, IE .

+1

flexbox, :

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/

0
source

Source: https://habr.com/ru/post/1688863/


All Articles