Change grid columns in Vue - vue.js

I have an outer Vue template:
<template>
<v-container fluid>
<div>
<v-row>
<v-col md="4" class="pa-1" v-for="i in allComponents" :key="i.id">
<gokb-reviews-title-card
:id="i.id.toString()"
#keys="addkeyFields"
/>
</v-col>
</v-row>
</div>
</v-container>
</template>
and an inner Vue template (gokb-reviews-title-card)
<template>
<v-card class="elevation-4 flex d-flex flex-column" v-if="!!title?.name">
<v-card-title primary-title>
<h5 class="titlecard-headline">{{ title.name }}</h5>
</v-card-title>
<v-card-text class="flex" v-for="(i, count) in title.identifiers" :key="i.id">
<div v-if="count == 0">{{ $tc('component.identifier.label', 2) }}</div>
<div class="titlecard-ids" :class="i.namespace.value">{{ i.namespace.value }}: {{ i.value }}</div>
</v-card-text>
<v-card-text class="flex" v-if="!!title?.history">
<div class="titlecard-history">{{ $t('component.title.history.label') }}</div>
<div class="titlecard-history">{{ title.history }}</div>
</v-card-text>
</v-card>
</template>
The row consists of 3 gokb-reviews-title-cards. I want to have it 4 cards.
I've tried to change it by adding cols="3" to the v-col as discussed in this question. This did not show any effect.
Adding a CSS .grid to the outer-most <div> (discussed here) can change the width of a card, but the maximum number of cards per row stays 3. The row is "half-filled" then. The CSS I tried is:
.reviews-grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
};
How can I make the <v-row> contain 4 <v-col>s thet each contain 1 card?

I think it is because you have md="4" in
<v-col md="4" class="pa-1" v-for="i in allComponents" :key="i.id">
if you change it to 3 it should work since it's a 12-based grid
<v-col md="3" class="pa-1" v-for="i in allComponents" :key="i.id">
in addition, your cols="3" might not be working because it only applies to widths narrower than the md breakpoint.
If you are using responsive layouts keep the md, but also define other widths, either through cols or xs. Otherwise just use cols

Related

How to place a button in the same row as v-card title?

I have a header, sub-header, icon and button on my v-card. My goal is to place my create button the right, but I can't seem to do that.
<template>
<v-row class="pl-5">
<v-card class="pl-5" elevation="0">
<v-card-title>
<v-icon left x-large color="primary">{{ icon }}</v-icon>
<span class="font-weight-bold">{{ title }}</span>
</v-card-title>
<v-card-subtitle> Subheader </v-card-subtitle>
<v-spacer></v-spacer>
<router-link v-if="type == 'index'" :to="`/${name.toLowerCase().replace(' ', '-')}/create`">
<v-btn outlined class="blue--text mt-5 mr-8">
<span>Create</span>
</v-btn>
</router-link>
</v-card>
</v-row>
</template>
<script>
export default {
props: {
icon: String,
name: String,
title: String,
subtitle: String,
type: String
},
components: {}
}
</script>
<style scoped></style>
If I move my <router-link> in <v-card-subtitle>
I get this
If I move my <router-link> in <v-card-title>
I get this
Can someone give me a push here ?
Fiddle
https://jsfiddle.net/bheng/h2u870dv/
If I do this:
<v-row class="pl-5">
<v-card-title>
<span class="material-icons">
favorite_border
</span>
<p class="font-weight-bold">TITLE</p>
<p class="caption">ST</p>
</v-card-title>
<v-spacer></v-spacer>
<v-btn>Create</v-btn>
</v-row>
I get
Button seems to locate at the place I wanted it to be, but the title and subtitle misalign very badly. I'm stuck now.
You can add div or v-col in v-row and use css to align items the way you want:
new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
icon: 'favorite_border',
name: 'link',
title: 'TITLE',
subtitle: 'https://fonts.google.com/icons?selected=Material+Icons',
type: 'index'
}
}
})
.myclass {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: flex-start;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#6.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Material+Icons" rel="stylesheet">
<div id="app">
<v-app>
<v-main>
<v-container>
<v-row class="pl-5">
<div class="myclass">
<v-card class="pl-5 mycard" elevation="0">
<v-card-title>
<v-icon left x-large color="primary">{{ icon }}</v-icon>
<span class="font-weight-bold">{{ title }}</span>
</v-card-title>
<v-card-subtitle> Subheader </v-card-subtitle>
<v-spacer></v-spacer>
</v-card>
<a v-if="type == 'index'" :href="`/${name.toLowerCase().replace(' ', '-')}/create`">
<v-btn outlined class="blue--text mt-5 mr-8">
<span>Create</span>
</v-btn>
</a>
</div>
</v-row>
</v-container>
</v-main>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
Your problem is that you're placing your button inside the v-card you declared to set the style of the title. And this card is just a square box since you haven't specified any width. If you set the elevation="1" you can see this clearly.
Just place your button outside the v-card and the v-spacer will work. Alternatively, you could also set the v-card width to 100%. Btw, you can also use the to prop in your v-btn, so there's no need to have a v-router-link.
Check this codesandbox I made: https://codesandbox.io/s/stack-71444864-v-spacer-example-0tx24n?file=/src/components/Example.vue
<v-row class="pl-5">
<v-card class="pl-5" elevation="0">
<v-card-title>
<v-icon left x-large color="primary"> mdi-home </v-icon>
<span class="font-weight-bold">Testing</span>
</v-card-title>
<v-card-subtitle class="pb-0"> Subheader </v-card-subtitle>
</v-card>
<v-spacer></v-spacer>
<v-btn to="/about" outlined class="blue--text mt-5 mr-8">
<span>Create</span>
</v-btn>
</v-row>
Update: v-cols and custom CSS with breakpoints conditionals
I saw you were interested to learn how to make this design using vuetify's grid. The advantage to use v-cols and breakpoint conditionals is that you'll have more control of your design over different viewports. Like on a mobile view. This is how I'd do it.
I start by splitting the grid in 2 columns, one for the title and one for the button, in cols view (previously known as xs (extra small)) I set the size of them to 12 columns and on sm (small) and up I set the size to 6 columns each. This way they are shown half and half.
The title column has no changes, on the buttom column I use the classes d-flex justify-end to move the button all to the right and align-center to center the button vertically at the middle of the v-row.
Then I use the breakpoint conditionals to activate the block property of the button and to apply paddings to the whole v-row, depending on the current viewport.
<v-row :class="$vuetify.breakpoint.smAndUp ? 'px-4' : ''">
<v-col cols="12" sm="6">
<v-card elevation="0">
<v-card-title>
<v-icon left x-large color="primary"> mdi-home </v-icon>
<span class="font-weight-bold">Testing</span>
</v-card-title>
<v-card-subtitle class="pb-0"> Subheader </v-card-subtitle>
</v-card>
</v-col>
<v-col cols="12" sm="6" class="d-flex justify-end align-center">
<v-btn to="/about" :block="$vuetify.breakpoint.xsOnly ? true : false" outlined class="blue--text">
<span>Create</span>
</v-btn>
</v-col>
</v-row>

How to support custom tiles in large screen in vuetify?

I have a dashboard that contains tiles in 3 rows, each row contains 5 tiles. Like the below picture
I am using the below code for tiles:
<v-layout row wrap>
<v-flex xs12 sm8 md4 lg4 xl4 class="lg5-custom pl-0 pb-0 tiles-cursor">
<v-card flat tile class="d-flex">
<v-img :src="require('img_url')" aspect-ratio="1" class="grey lighten-2">
</v-img>
<div class="content">
<h3 align="center">A</h3>
</div>
</v-card>
</v-flex>
<v-flex xs12 sm8 md4 lg4 xl4 class="lg5-custom pl-0 pb-0 tiles-cursor">
<v-card flat tile class="d-flex">
<v-img :src="require('img_url')" aspect-ratio="1" class="grey lighten-2">
</v-img>
<div class="content">
<h3 align="center">A</h3>
</div>
</v-card>
</v-flex>
... so on
</v-layout>
Below is my CSS code to customize the tiles:
#media (min-width: 1264px) and (max-width: 1903px) {
.flex.lg5-custom {
width: 20%;
max-width: 20%;
flex-basis: 20%;
}
.flex.lg10-custom {
width: 40%;
max-width: 40%;
flex-basis: 40%;
}
}
Even small screen sometimes 3rd row last tiles don't support.
.flex.lg10-custom CSS used for 3rd rows last tile.
I wanted to support this landing page for all screen (especially large screen). Any idea?
So, I have resolved it by using v-row and v-col instead of v-flex. However, all the tiles got small compare to the previous one because the entire row size is 12 and I divided by 5 so, that I can only utilize only 10, not 12. I had to leave 1 from left and 1 from the right to make it center. Below is my code:
<v-container fluid>
<v-row justify="center">
<v-col cols="2" class="pb-1 pt-1 pl-1 pr-1">
<v-card elevation="23" class="secondary ml-0 mr-0 mt-0 mb-0 change-mouse-pointer">
<v-img :src="require('img_url')" aspect-ratio="1" class="grey lighten-2">
</v-img>
<div class="content">
<h3 align="center">A</h3>
</div>
</v-card>
</v-col>
<v-col cols="2" class="pb-1 pt-1 pl-1 pr-1">
<v-card elevation="23" class="secondary ml-0 mr-0 mt-0 mb-0 change-mouse-pointer">
<v-img :src="require('img_url')" aspect-ratio="1" class="grey lighten-2">
</v-img>
<div class="content">
<h3 align="center">A</h3>
</div>
</v-card>
</v-col>
... so on
</v-row>
.... last row last col
<v-row justify="center">
... first 3 will be the same as before
<v-col cols="4" class="pb-1 pt-1 pl-1 pr-1">
<v-card elevation="23" class="secondary d-flex" height="50%">
<v-img :src="require('img_url')" aspect-ratio="1" class="grey lighten-2">
</v-img>
<div class="content">
<h3 align="center">A</h3>
</div>
</v-card>
</v-col>
</v-row>
</v-container>
If anyone wants the full solution, please comment below.

how to align item horizontally in vuetify

i've been stuck for hours just to align an item vertically and horizontally in v-card. this image below is what i currently have, i just have to align the item vertically but i dont know how. can anyone help me? thanks in advance
My code :
<div class="pt-3">
<v-card class="pa-3">
<v-row align="center" justify="center" v-bind:style="{ height: deviceHeight * 0.6 + 'px',}">
<v-col class="fill-height" height="500">
<v-card class="text-center grey" height="100%">
<div align="center" justify="center">
<v-icon>mdi-camera</v-icon>
<h3>Upload</h3>
</div>
</v-card>
</v-col>
</v-row>
</v-card>
</div>
computed: {
deviceHeight(){
return this.$vuetify.breakpoint.height;
},
deviceWidth(){
return this.$vuetify.breakpoint.width;
},
},
The align and justify props are used for some Vuetify components, but they won't work on a native HTML div. Instead use the appropriate classes on the v-card...
<v-card class="text-center grey d-flex flex-column align-center justify-center" height="100%">
<div>
<v-icon>mdi-camera</v-icon>
<h3>Upload</h3>
</div>
</v-card>
Demo
v-row behaves as the flex-container and all the props like justify or align or any flex container property will work to it only. Just change ur div to v-row. Althought there is one problem with that is v-row have some negative margin which you can rid off by using no-gutters
<div class="pt-3">
<v-card class="pa-3">
<v-row align="center" justify="center" v-bind:style="{ height: deviceHeight * 0.6 + 'px',}">
<v-col class="fill-height" height="500">
<v-card class="text-center grey" height="100%">
<v-row no-gutters align="center" justify="center">
<v-icon>mdi-camera</v-icon>
<h3>Upload</h3>
</div>
</v-card>
</v-col>
</v-row>
</v-card>
</div>

I cant vertically align items in center #vuetify

i've been looking for 3 hours and cant find solution for my problem, dont know what am i doing wrong
All i want is to vertically align these 3 v-flex elements
<template>
<div class="home">
<v-container fluid class="pa-0">
<v-img :src="require('#/assets/images/background.jpg')" max-height="100%">
<v-layout align-center column>
<v-flex class="mb-2">
<span class="primary--text text-uppercase display-3 font-weight-thin">List</span>
<span class="white--text text-uppercase display-3 font-weight-thin">Series</span>
</v-flex>
<v-flex class="mb-4">
<h4 class="subheading grey--text">Follow the series you've been watching or are still watching!</h4>
</v-flex>
<v-flex>
<v-btn color="primary" depressed flat outline to="/add">
go to add
</v-btn>
</v-flex>
</v-layout>
</v-img>
</v-container>
</div>
</template>
One solution would be to move the image out of the container. Then use style="height: 100%;" align-center d-flex on container to make it fill image area and display contents vertically in the middle. Also you might want to consider image max-height="100vh" to prevent scrolling on smaller screens.
new Vue({
el: '#app'
})
<link href="https://cdn.jsdelivr.net/npm/vuetify#1.2.2/dist/vuetify.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#1.2.2/dist/vuetify.min.js"></script>
<div id="app">
<template>
<div class="home">
<v-img src="https://images.unsplash.com/photo-1562696482-77619dec0ae7?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1351&q=80" max-height="100%">
<v-container style="height: 100%;" align-center d-flex fluid class="pa-0">
<v-layout align-center column>
<v-flex class="mb-2">
<span class="primary--text text-uppercase display-3 font-weight-thin">List</span>
<span class="white--text text-uppercase display-3 font-weight-thin">Series</span>
</v-flex>
<v-flex class="mb-4">
<h4 class="subheading grey--text">Follow the series you've been watching or are still watching!</h4>
</v-flex>
<v-flex>
<v-btn color="primary" depressed flat outline to="/add">
go to add
</v-btn>
</v-flex>
</v-layout>
</v-img>
</v-container>
</div>
</template>
</div>

Multi line card carousel card for Vuetify

How can I achieve the multi card inside carousel similar to this Demo in Vuetify
<v-carousel>
<v-carousel-item
v-for="(item,i) in items"
:key="i"
:src="item.src">
<card></card> // card will be here
</v-carousel-item>
</v-carousel>
I would like to show 6 cards per slide, 3 columns and 2 rows. Or if there are any plugins available
You need two "v-for", the first with limit 2, second with limit 6. And if you want 2 rows look the vuetify official documentation grid system documentation
Try this, it is without style of your example
<v-flex>
<v-carousel hide-delimiters style="box-shadow: 0px 0px">
<v-carousel-item v-for="i in 2" :key="i">
<v-layout row>
<v-flex sm4 v-for="j in 6" :key="j" pl-2 pr-2>
<v-card>
<v-img
src="https://cdn.vuetifyjs.com/images/cards/desert.jpg"
aspect-ratio="0.8"
></v-img>
<v-card-title primary-title>
<div>
<h3 class="headline mb-0">Card {{i}}-{{j}}</h3>
<div> Card text </div>
</div>
</v-card-title>
</v-card>
</v-flex>
</v-layout>
</v-carousel-item>
</v-carousel>
</v-flex>
It seems like Carousel is not the best component to use in this case.
It might use vuetify Slide groups instead: https://vuetifyjs.com/en/components/slide-groups/
Or a mix of both