opH*_*AME 12 css vuejs2 vuetify.js
对此感到疯狂,我想将 vuetify2 项目中的所有 v-card 大小相等。我的中心(v-card-text)有不同的字符数(文本)。使用 v-card-text 的固定高度进行测试,但如果文本较长,则没有预期的滚动条。
这是一个 v-card 组件的标记:
<template>
<v-card class="elevation-5" fill-height>
<v-card-title primary-title>
<h3 class="headline mb-0">{{ name }}</h3>
</v-card-title>
<v-card-text>
<div class="body-1">{{ description }}</div>
<v-divider light style="margin-top:15px;" />
<v-divider light />
</v-card-text>
<v-card-actions v-if="showButtons">
<v-btn color="green">
<a :href="url">VISIT</a>
</v-btn>
</v-card-actions>
</v-card>
</template>
Run Code Online (Sandbox Code Playgroud)
这是父组件:
<template>
<div>
<v-row class="ma-2">
<v-col md="4" class="pa-3" v-for="i in items" :key="i.id">
<Item :show-buttons="true" :item="i" />
</v-col>
</v-row>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
父级位于:
<v-content>
<v-container fluid ma-0 pa-0>
<router-view />
</v-container>
</v-content>
Run Code Online (Sandbox Code Playgroud)
请看这个屏幕,可能这让我的英语不好更容易理解。
ski*_*tle 16
我想你正在寻找这样的东西:
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
items: [
{ id: 1, name: 'A', description: 'Short', showButtons: true },
{ id: 2, name: 'B', description: 'Short', showButtons: false },
{ id: 3, name: 'C', description: 'Longer text that wraps onto multiple lines', showButtons: true }
]
}
}
})
Run Code Online (Sandbox Code Playgroud)
#app {
max-width: 500px;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://unpkg.com/@mdi/font@3.9.97/css/materialdesignicons.css" rel="stylesheet">
<link href="https://unpkg.com/vuetify@2.0.17/dist/vuetify.css" rel="stylesheet">
<script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
<script src="https://unpkg.com/vuetify@2.0.17/dist/vuetify.js"></script>
<div id="app">
<v-app>
<div>
<v-row class="ma-2">
<v-col md="4" class="pa-3 d-flex flex-column" v-for="i in items" :key="i.id">
<v-card class="elevation-5 flex d-flex flex-column">
<v-card-title primary-title>
<h3 class="headline mb-0">{{ i.name }}</h3>
</v-card-title>
<v-card-text class="flex">
<div class="body-1">{{ i.description }}</div>
<v-divider light style="margin-top:15px;"></v-divider>
<v-divider light></v-divider>
</v-card-text>
<v-card-actions v-if="i.showButtons">
<v-btn color="green">
<a>VISIT</a>
</v-btn>
</v-card-actions>
</v-card>
</v-col>
</v-row>
</div>
</v-app>
</div>
Run Code Online (Sandbox Code Playgroud)
我已经在几个地方添加了 classes d-flex
, flex-column
, and flex
,但除此之外它应该等同于问题中发布的代码。该d-flex flex-column
让父母柔性盒列,然后flex
将孩子flex: auto
,使之延伸,以填补空间。这里有一个微妙之处,可用空间由最高的项目定义,因此存在各种圆形。
小智 8
您只需要在 v-row 中将 'align' 属性设置为“stretch”:
<template>
<div>
<v-row align="stretch" class="ma-2">
<v-col md="4" class="pa-3" v-for="i in items" :key="i.id">
<Item :show-buttons="true" :item="i" />
</v-col>
</v-row>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
class="fill-height"
卡片上对我有用:
<v-row>
<v-col v-for="i in 8" :key="i" lg="4">
<v-card class="fill-height">...</v-card>
</v-col>
</v-row>
Run Code Online (Sandbox Code Playgroud)
设置文本区域的高度和溢出:
<v-card-text style="overflow-y: auto; height:100px" >
<div class="body-1">{{ description }}</div>
<v-divider light style="margin-top:15px;" />
<v-divider light />
</v-card-text>
Run Code Online (Sandbox Code Playgroud)
最好通过 a 来完成class
,但我style
在这里使用是为了便于掌握。