【问题标题】:css grid with background - scroll when grid is bigger than the background带背景的 CSS 网格 - 当网格大于背景时滚动
【发布时间】:2018-10-10 19:01:27
【问题描述】:

我有一个可以增长的表格,一旦它增长它可以推动网格高度大于背景。 我希望网格本身将在背景顶部滚动。 我尝试使用溢出但没有成功。

你可以看到问题here

这里是相关代码:

.wrapper {
  background-repeat: no-repeat;
  background-position: top center;
  height: 1024px;
  min-width: 1055px;
  display: grid;
  grid-template-columns: 0.1fr 2.8fr 0.1fr;
  grid-gap: 10px;
  grid-template-rows: 100px auto auto 100px;
  font-family: 'roboto',sans-serif;
  overflow:visible;
  /*grid-auto-rows: minmax(100px, auto);*/
  /*border: 1px solid;*/
}
.wrapper > div {
  display: flex;
  justify-content: center;
  /* align-items: center; */
  font-size: 16px;
  font-weight: 400;
  /* border: solid 1px; */
  color: #39393ac7 /*#39393A*/;
}

.header {
  grid-column: 2 ;
}
.herbTable {
  grid-column: 2 ;
}
.chart {
  grid-column: 2 ;
}
.footer {
  grid-column: 1 / -1 ;
  grid-row: 4;
}

 @media screen and (max-width : 1439px) /*and (max-width : 1439px) */
{
  .wrapper {
    background-image: url("~/static/bg1440px.jpg");
    background-size: cover;
    /* background-size: 1024px; */
    /* width: 1024px; */
  }
}

@media screen and (min-width : 1440px)
{
  .wrapper {
    background-image: url("~/static/bg1440px.jpg");
    background-size: 1440px auto;
    /* height: 1024px; */
    width: 1440px;
  }
}
<template>
  <div class="wrapper">
      <appHeader class="header"></appHeader>
      <loading :active.sync="isLoading" :can-cancel="false"></loading>
      <appHerbsTable v-if="!isLoading" class="herbTable"></appHerbsTable>
      <appChart v-if="!isLoading" class="chart">chart</appChart>
      <div class="footer"></div>
  </div>
</template>

【问题讨论】:

    标签: css vue.js overflow css-grid


    【解决方案1】:
    .wrapper {
      /* overflow: visible; */
      overflow: auto; /* NEW */
    }
    

    【讨论】:

      【解决方案2】:

      由于您有固定的列宽,这应该很容易将您的 css 更改为:

      .herbTable thead {
        display: block; /*inline-block should also be ok*/
      }
      .herbTable tbody {
        display: block;
        max-height: 300px;
        overflow-y: scroll;
      }
      

      .. 你将不得不修改你的 td 宽度以使它再次看起来不错

      编辑:(我希望我终于明白你所说的网格是什么意思)

      html {
        height: 100%;
      }
      body {
        height: 100%;
        box-sizing: border-box;
        padding: 8px;
        margin: 0;
      }
      .wrapper {
        height: 100%;
        overflow-y: auto;
      }
      

      ..希望这会有所帮助..

      【讨论】:

      • 嗨,这将滚动添加到herbTable整个网格!不要到网格中的 div
      • @EldadT:也查看了您对其他帖子的评论.. 那么您想要什么?单元格、正文或整个表格中的滚动条(滚动时会隐藏标题)?
      • @EldadT:如果这就是你要找的东西,请告诉我……这样我就可以删除我帖子中的错误部分
      猜你喜欢
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      • 2019-08-14
      相关资源
      最近更新 更多