如何设置vuetify卡的高度

时间:2018-04-20 20:50:54

标签: css vue.js vuetify.js

我正在尝试添加一张带有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

6 个答案:

答案 0 :(得分:7)

  

使用Vuetify,你可以做几乎所有事情,但仔细阅读文档。如果你看一下api部分的问题,你会注意到将要做的工作的道具高度。

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

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

<v-card height="100%">

See it in action

答案 1 :(得分:2)

我不知道您是否可以解决您的问题...但是对于您的情况,您可以在此处看到问题的解决方案: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>

答案 2 :(得分:1)

我对接受的答案进行了评论:

<v-card height="100%">

如果您有v卡操作(卡页脚),则会出现样式问题。

要均衡v文本卡组件,您应该创建一个自定义(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卡组件中,如下所示:

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

如果有人遇到相同的问题,我希望这会有所帮助。

贷记Sindrepm and his CodePen

答案 3 :(得分:1)

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

答案 4 :(得分:0)

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

答案 5 :(得分:0)

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

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