Getting crazy with this, i want to size all v-cards in an vuetify2 project equal. My the center (v-card-text) has different count of chars (text). Tested with a fixed height of v-card-text, but no scrollbar as expected if text is longer.
This a the markup for one v-card component:
<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>
This is the parent component:
<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>
The Parent is placed in:
<v-content>
<v-container fluid ma-0 pa-0>
<router-view />
</v-container>
</v-content>
Please see this screen, may be this makes my bad english better to understand.
I think you're looking for something like this:
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 }
]
}
}
})
#app {
max-width: 500px;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://unpkg.com/@mdi/[email protected]/css/materialdesignicons.css" rel="stylesheet">
<link href="https://unpkg.com/[email protected]/dist/vuetify.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/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>
I've added the classes d-flex
, flex-column
, and flex
in a few places but otherwise it should be equivalent to the code posted in the question. The d-flex flex-column
makes the parent a flex-box column and then flex
sets the child to flex: auto
, so that it stretches to fill the space. There's a subtlety here in that the available space is defined by the tallest item, so there's a circularity of sorts.
You just have to set 'align' property to "stretch" in v-row:
<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>
Set the height and the overflow in the text area:
<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>
It is better to do it by a class
, but I use style
here for an easy grasp.
class="fill-height"
on the cards works for me:
<v-row>
<v-col v-for="i in 8" :key="i" lg="4">
<v-card class="fill-height">...</v-card>
</v-col>
</v-row>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With