html - MS Edge 无法正确呈现嵌套的 Flex 布局

标签 html css flexbox microsoft-edge

这是显示我遇到的问题的布局,也可以在 https://jsfiddle.net/51z7vt23/ 找到

.box {
     width: auto;
     height: 40px;
     border: 1px solid red;
     flex: 0 0 auto;
     position: relative;
}
.txt {
     overflow: hidden;
     text-overflow: ellipsis;
     white-space: nowrap;
     font-size: 18px;
     flex: 1 0 auto;
     width: 0px;
     position: relative;
}
.container {
     font-size: 16px;
     line-height: 3rem;
     box-sizing: border-box;
     position: relative;
     display: flex;
     padding: 0;
     margin: 0;
     max-width: 100%;
     text-align: start;
     flex: 0 0 auto;
      width: auto;
      height: auto;
}
.container2 {
      font-size: 16px;
      line-height: 3rem;
      box-sizing: border-box;
      position: relative;
      display: flex;
      flex: 1 0 auto;
      padding: 0;
      margin: 0;
      max-width: 100%;
      text-align: start;
      align-items: center;
      height: auto;           
}
.parent {
       width: 400px;
       border: 1px solid lime;
}
<div class="parent">
     <div class="container">
          <div class="container2">
               <div class="box">YES</div>
                <div class="txt">REALLY REALLLY REAAAAALLLY REAAAAALLLY REAAAAALLLY BEAUTIFULL TEXT, PERHAPS THE MOST BEAUTIFULL TEXT IN THE WORLD</div>
           </div>
           <div class="box">NO</div>
     </div>
</div>

这段代码在 Chrome 上运行良好,并提供了预期的结果: enter image description here 但是使用 MS Edge 我可以看到“否”框被推出容器边界: enter image description here

我使用的 MS Edge 版本是 44.17763.771.0

有谁知道如何使用 MS EDGE 使其按预期工作?

最佳答案

您可以删除 .container2 上的 max-width:100%; ,这太多了,因为宽度要与另一个元素共享。您可以将它变成 min-width:100%;+/或 overflow:hidden; 作为其大小的回流/重新计算。

下面的演示

.box {
  width: auto;
  height: 40px;
  border: 1px solid red;
  flex: 0 0 auto;
  position: relative;
}

.txt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
  flex: 1 0 auto;
  width: 0px;
  position: relative;
}

.container {
  font-size: 16px;
  line-height: 3rem;
  box-sizing: border-box;
  position: relative;
  display: flex;
  padding: 0;
  margin: 0;
  max-width: 100%;
  text-align: start;
  flex: 0 0 auto;
  width: auto;
  height: auto;
}

.container2 {
  font-size: 16px;
  line-height: 3rem;
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex: 1 1 auto;
  padding: 0;
  margin: 0;
  text-align: start;
  align-items: center;
  height: auto;
  min-width: 0;
  overflow: hidden;
}

.parent {
  width: 400px;
  border: 1px solid lime;
}
<div class="parent">
  <div class="container">
    <div class="container2">
      <div class="box">YES</div>
      <div class="txt">REALLY REALLLY REAAAAALLLY REAAAAALLLY REAAAAALLLY BEAUTIFULL TEXT, PERHAPS THE MOST BEAUTIFULL TEXT IN THE WORLD</div>
    </div>
    <div class="box">NO</div>
  </div>
</div>

fork https://jsfiddle.net/8f9suq7k/

关于html - MS Edge 无法正确呈现嵌套的 Flex 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58593221/

相关文章:

html - 为什么 flex 元素在这个 div 中增长不均匀?

jquery - 边框下的白线

css - firefox 不将 css 转换应用于子元素

jquery - 一页上有 2 个不同的 Owl Carousel slider ,宽度不同

javascript - 调整浏览器大小时 bootstrap scrollspy 错误

css - 如何更改列显示顺序移动/平板电脑 View CSS Wordpress?

html - 图像未显示在 Flex 容器中

html - 影响 Bootstrap 3 布局的 CSS Flexbox

javascript - 使用带有 anchor 标记的 curtain.js 进行站点导航

javascript - 在带有服务器通信的android webview中首次单击时无法获取数据