【问题标题】:Button text not displayed when using display flex (only in IE) [duplicate]使用 display flex 时不显示按钮文本(仅在 IE 中)[重复]
【发布时间】:2018-04-19 16:43:18
【问题描述】:

在 html 中,我有一个按钮,其中包含两个图标和一个带文本的 span。 在 css 中,我使用 flex 和 overflow 属性来截断太长的文本。该代码适用于除 IE 之外的所有浏览器。 这是 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;
  }
}

提前致谢, 标记

【问题讨论】:

    标签: html css internet-explorer flexbox


    【解决方案1】:

    您可以删除span 上的flex 属性。

    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>

    【讨论】:

      【解决方案2】:

      浏览器有不同的 CSS flex'。这应该适用于 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:https://jsfiddle.net/fu6kfhw9/7/

      您也许可以删除所有不同的 flex,只保留普通的和 IE 的。

      【讨论】:

        【解决方案3】:

        如果你想保留 flexbox,你可以为 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/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-11-28
          • 2015-10-13
          相关资源
          最近更新 更多