如何设置vuetify卡的高度

新手上路,请多包涵

我正在尝试使用 vue 和 vuetify 添加一张卡片,这将占用我容器中的空间,使用 v-flex 创建一个水平卡片,其垂直行为方式相同。我尝试使用填充高度、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

原文由 Darwin 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

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

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

 <v-card height="100%">

看到它在行动

原文由 Roland 发布,翻译遵循 CC BY-SA 4.0 许可协议

我评论了接受的答案:

 <v-card height="100%">

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

要平衡 v-text-card 组件,您应该创建一个自定义 (SCSS) 类:

 .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;
}

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

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

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

感谢 Sindrepm 和他的 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>

原文由 JustDevelop 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题