【问题标题】:Flex-box discrepancy between Chrome and FirefoxChrome 和 Firefox 之间的 Flex-box 差异
【发布时间】:2019-08-29 23:43:44
【问题描述】:

我有一个有两列的表。我正在使用 flex 列,以便在每个第一列项目上都有第二列中心。

问题是 FireFox 和 Chrome 的显示不一样。我必须在 Chrome 中将高度设置为 1px 才能将一个 div 拉伸到 100% 高度。这使得FireFox中的表被砸烂了。

https://codepen.io/anon/pen/bJBWMK

SCSS

   @import "bourbon";

   table, td {
   border-collapse: collapse;
   border: 1px solid black;
   }
   .container {
   height: 1px;
   }
   .flex-wrap {
   @include display(flex);
   @include flex-direction(column);
   @include justify-content(space-around);
   height:100%;
   }

HTML

<table>
   <thead>
      <tr>
         <th>Col 1</th>
         <th>Col 2</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td class="container">
            <div class="flex-wrap">
               <div>
                  First Div <br/>
                  First Div <br/>
                  First Div <br/>
               </div>
               <div>
                  Second Div <br/>
                  Second Div <br/>
                  Second Div <br/>
               </div>
            </div>
         </td>
         <td class="container">
            <div class="flex-wrap">
               <div>Center First Div</div>
               <div>Center Second Div</div>
            </div>
         </td>
      </tr>
   </tbody>
</table>

【问题讨论】:

  • 最好将内容(第一个 div / 第二个 div)分成两行。以您当前的结构,即使使用 1px hack,如果您将任何一个内容从 3 行内容更改为 2 行内容,那么第二列中的对齐也会受到干扰。

标签: css google-chrome firefox flexbox


【解决方案1】:

我看不出这段代码可以工作的任何原因。您的 height: 1px 技巧是一个黑客。这是非标准化代码。因此浏览器的行为可能会有所不同。

如果您必须保持这种代码结构,请考虑从height: 1px 切换到min-height: 1px

【讨论】:

  • Min-height 破坏了 Chrome 和 Firefox。我试过了。
  • 那么我唯一能想到的就是让 div 父级 flex 容器,这样他们就可以将 div 拉伸到整个高度。但即使这样可行,我也不认为它在浏览器中是稳定的。
猜你喜欢
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-25
  • 1970-01-01
  • 2012-08-23
  • 2011-08-30
  • 1970-01-01
相关资源
最近更新 更多