如何设置vuetify卡的高度

How to set the height of vuetify card

我正在尝试添加一张带有 vue 和 vuetify 的卡片,它将占用我容器中的 space,使用 v-flex 创建一个水平卡片,该卡片在垂直方向上的作用相同。我尝试使用 fill-height、child-flex 等添加 100% 的高度样式,但我无法获得卡片的大小来填充容器。调整高度的正确方法是什么?

参考:https://vuetifyjs.com/en/components/cards

<div id="app">
  <v-app id="inspire">
    <v-toolbar color="green" dark fixed app>
      <v-toolbar-title>My Application</v-toolbar-title>
    </v-toolbar>
    <v-content >
      <v-container fluid fill-height >
        <v-layout
          justify-center
          align-center 
        >
          <v-flex text-xs-center >
              <v-card class="elevation-20" >
              <v-toolbar dark color="primary">
                <v-toolbar-title>I want this to take up the whole space with slight padding</v-toolbar-title>
                <v-spacer></v-spacer>
              </v-toolbar>
              <v-card-text>

              </v-card-text>

            </v-card>
          </v-flex>
        </v-layout>
      </v-container>
    </v-content>
    <v-footer color="green" app inset>
      <span class="white--text">&copy; 2018</span>
    </v-footer>
  </v-app>
</div>

示例:https://codepen.io/anon/pen/LmVJKx

您可以尝试为容器的每个子元素添加高度 100%。

Vuetify 对于 height 道具说:手动定义卡片的高度

因此,在 v-card 元素中添加高度如下:

<v-card height="100%">

See it in action

我不知道您是否可以解决您的问题...但是对于您的情况,您可以在此处查看问题的解决方案:https://codepen.io/carlos-henreis/pen/djaQKb

<div id="app">
  <v-app id="inspire">
    <v-toolbar color="green" dark fixed app>
      <v-toolbar-title>My Application</v-toolbar-title>
    </v-toolbar>
    <v-content >
      <v-container fluid fill-height >
        <v-layout
          justify-center
          align-center 
        >
          <v-flex text-xs-center fill-height>
              <v-card class="elevation-20" height='100%'>
              <v-toolbar dark color="primary">
                <v-toolbar-title>I want this to take up the whole space with slight padding</v-toolbar-title>
                <v-spacer></v-spacer>
              </v-toolbar>
              <v-card-text>

              </v-card-text>

            </v-card>
          </v-flex>
        </v-layout>
      </v-container>
    </v-content>
    <v-footer color="green" app inset>
      <span class="white--text">&copy; 2017</span>
    </v-footer>
  </v-app>
</div>

它将固定高度并在垂直方向添加滚动条

<v-card class="scroll-y"  style="height: 650px">

我对已接受的答案发表评论说:

<v-card height="100%">

如果您有 v-card-actions(卡片页脚),则会出现样式问题。

要均衡 v-text-card 组件,您应该创建自定义 (SCSS) class:

.flexcard {
  display: flex;
  flex-direction: column;
}
// Add the css below if your card has a toolbar, and if your toolbar's height increases according to the flex display.
.flexcard .v-toolbar {
  flex: 0;
}

然后,将 class 添加到 v-card 组件中,如下所示:

<v-card class="flexcard" height="100%">
  ... Your code here
</v-card>

如果有人面临同样的问题,我希望这对您有所帮助。

感谢 Sindrepm and his CodePen

除此之外:codepen不包含任何卡片图片。因此,如果您在像这样的 v-card 组件中使用 v-img 组件:

<v-card 
  class="flexcard"
  height="100%">
  <v-img
    height="200px" 
    :src=".\sample\image.png">
  </v-img>
...
<v-card>

您可能想要修复它们的最大高度以确保您的 v-card 组件上的布局相同:

<v-card 
  class="flexcard"
  height="100%">
  <v-img
    height="200px"
    max-height="200px"
    :src=".\sample\image.png">
  </v-img>
...
<v-card>

我用过 100vh 或 vw。它使它适合整个高度。