【问题标题】:CSS Grid Container Width Calculation Wrong in FFFF中的CSS网格容器宽度计算错误
【发布时间】:2019-03-12 21:25:19
【问题描述】:

以下 CSS Grid 代码在 Chrome 和 IE 中的行为与在 FF 中的行为不同。

https://codepen.io/inkOrange/pen/XGzeMo 当溢出的内容不适合时,布局被设计为水平滚动,正如我在这个演示中所强制的那样。

外部容器固定为 900px。在 Chrome (72.0) 中检查 .TableRow 网格容器时,宽度为:1010px,强制水平滚动条。

但在 FF (65.0) 中,它读取的宽度小于其边界框:885px,不会导致溢出/滚动条。

.TableRow 的内容在两个浏览器中都超出了边界容器,但 FF 似乎无法解析基于 css-grid 元素的真实宽度。

我该如何为 FF 解决这个问题?我希望 .TableWrapper 上有一个滚动条

HTML:

<div style="width: 900px; overflow: auto;">
  <section class="TabularListing">
    <section class="TableWrapper">
      <div class="TableHeaderContainer">
        <div></div>
        <div><label style="cursor: pointer;">Dest</label></div>
        <div><label style="cursor: pointer;">Opened</label></div>
        <div><label style="cursor: pointer;">Cube</label></div>
        <div><label style="cursor: pointer;">Y<em>(ft)</em></label></div>
        <div><label style="cursor: pointer;">Z<em>(ft)</em></label></div>
        <div><label style="cursor: pointer;">Z<em>(ft)</em></label></div>
        <div><label style="cursor: pointer;">Weight</label></div>
      </div>
      <div class="TableBodyContainer">
        <div class="TableRow">
          <div></div>
          <div><span data-filterable="true" data-value="BILL">BILL</span></div>
          <div><span>1380233679000</span></div>
          <div><span>72</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>       
        </div>
        <div class="TableRow">
          <div></div>
          <div><span data-filterable="true" data-value="BILL">BILL</span></div>
          <div><span>1380233679000</span></div>
          <div><span>72</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>       
        </div>
        <div class="TableRow">
          <div></div>
          <div><span data-filterable="true" data-value="BILL">BILL</span></div>
          <div><span>1380233679000</span></div>
          <div><span>72</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>       
        </div>
        <div class="TableRow">
          <div></div>
          <div><span data-filterable="true" data-value="BILL">BILL</span></div>
          <div><span>1380233679000</span></div>
          <div><span>72</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>       
        </div>
        <div class="TableRow">
          <div></div>
          <div><span data-filterable="true" data-value="BILL">BILL</span></div>
          <div><span>1380233679000</span></div>
          <div><span>72</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>
          <div><span>94</span></div>       
        </div>
     </div>
    </section>
  </section>
</div>

CSS:

.TabularListing {
  position: relative;
    .TableWrapper {
      display: grid; 
      grid-template-rows: 64px calc(136px); 
      overflow: auto hidden;
      .TableHeaderContainer {
        background-color: white; 
      min-height: 24px; 
      max-height: 64px; 
      overflow: hidden; 
      display: grid; 
      width: 100%; 
      grid-template-columns: 50px 250px 180px 130px minmax(100px, 12.5%) minmax(100px, 12.5%) minmax(100px, 12.5%) minmax(100px, 15%); 
      border-bottom: 1px solid rgb(224, 224, 224);
        > div {
          box-shadow: rgba(0, 0, 0, 0) 0px -1px 0px 0px inset, rgb(224, 224, 224) 0px -1px 0px inset; transition: all 0.5s ease 0s; 
          opacity: 0.75; 
          padding: 20px 38px 20px 60px; 
          cursor: default; 
          overflow: hidden; 
          text-overflow: ellipsis; 
          font-size: 1.3rem; 
          font-weight: 400; 
          text-align: left; 
          line-height: 1.5rem; 
          color: rgb(33, 33, 33); 
          vertical-align: top; 
          background-color: white; position: relative;
        }
      }
      .TableBodyContainer {
        overflow: hidden auto; width: 100%;
        .TableRow {
          display: grid; 
          grid-template-columns: 50px 250px 180px 130px minmax(100px, 12.5%) minmax(100px, 12.5%) minmax(100px, 12.5%) minmax(100px, 15%); transition: box-shadow 0.25s ease 0s; 
          background-color: white; 
          border-bottom: 1px solid rgb(224, 224, 224); 
          cursor: pointer; 
          min-height: auto;
          > div {
            padding: 20px 40px 20px 60px; 
            cursor: default; 
            overflow: hidden; 
            text-overflow: ellipsis; 
            font-size: 1.3rem; 
            text-align: right; 
            position: relative;
          }
        }
      }
    }
}

【问题讨论】:

    标签: html css firefox css-grid


    【解决方案1】:

    当您从 .TableHeaderContainer 中删除 overflow: hidden 时,它似乎可以跨浏览器工作。

    revised codepen

    【讨论】:

    • 有时就这么简单,谢谢@Michael_B。这确实可以解决问题。我一直在看行,而不是在标题中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多