【问题标题】:Vuetify Overflow On A Flex Column Causing Entire Page to OverflowFlex 列上的 Vuetify 溢出导致整个页面溢出
【发布时间】:2021-05-04 12:42:55
【问题描述】:

在我的三列 Vuetify 布局中,我有一列非常高。我只希望此列有一个滚动条。但是,下面的代码导致整个页面溢出!有什么帮助吗?

<template>
  <v-container fluid class="secondary fill-height">
    <v-row class="fill-height ">
      <v-col class="accent rounded overflow-y-auto" cols="2">
        <div class="text-center">
          Lorem ipsum....super long
        </div>
      </v-col>
      <v-col class="primary rounded" cols="5">Editor</v-col>

      <v-col class="success rounded" cols="5">Stage Stuff</v-col>
    </v-row>
  </v-container>
</template>

【问题讨论】:

    标签: flexbox vuetify.js css-grid


    【解决方案1】:

    将 max-height: calc(100vh - 48px) 样式添加到包含长内容的 div 中。

    <template>
      <v-container fluid class="secondary fill-height">
        <v-row class="fill-height">
          <v-col class="accent rounded overflow-y-auto" cols="2">
    
            <!-- Add max-height to this div so its height won't expand past the viewport's height -->
            <div class="text-center" style="max-height: calc(100vh - 48px)">
              Lorem ipsum....super long
            </div>
    
    
          </v-col>
          <v-col class="primary rounded" cols="5">Editor</v-col>
          <v-col class="success rounded" cols="5">Stage Stuff</v-col>
        </v-row>
      </v-container>
    </template>
    

    基本上,当 div 的内容变长时,您只需限制 div 的最大高度。 100vh 是视口的全高。 48px 是 &lt;v-container /&gt; 和 &lt;v-col /&gt; 的累积垂直填充。

    See live demo.

    注意: 48px 来自整个页面的累积垂直填充/边距/边框。在我们的例子中,它是 &lt;v-container/&gt; 的 12px 顶部和底部填充加上 &lt;v-col/&gt; 的 12px 顶部和底部填充。当我们想要实现完整的寻呼机 div 时,这是一个已知的技巧。你可以在这里阅读更多:https://dev.to/lennythedev/css-gotcha-how-to-fill-page-with-a-div-270j

    【讨论】:

    • 谢谢!那是完美的。你是怎么想到 48px 的?
    • 对不起,如果我不够清楚。我已经更新了我的答案来解释 48px 的来源。
    猜你喜欢
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2018-04-09
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多