Vuetify - make square v-card with centered text (both axis) - vue.js

I am trying to make a v-card that has card text centered right in the middle of the square. I tried using v-spacer and some other CSS classes that vuetify comes with, but unfortunately while text stays centered horizontally, I am having trouble making it also center vertically.
This code has almost everything working except the vertical centering of the middle text
<v-container fluid>
<v-row>
<v-col cols="6" sm="4">
<v-card rounded color="info">
<v-responsive aspect-ratio="1">
<v-card-title>
Top left - correct
</v-card-title>
<v-card-text class="text-center white--text">
middle center
</v-card-text>
<v-card-actions class="justify-center white--text">
bottom center
</v-card-actions>
</v-responsive>
</v-card>
</v-col>
</v-row>
</v-container>
Here is a JS fiddle with example: https://jsfiddle.net/mrpquke4/3/
Try resizing the browser window with the example above and you will see v-card stays square shape while growing or shrinking(as desired), text stays centered horizontally (as desired), text is not centered vertically (the problem).
JSFiddle:
Desired Result:

Use this css:
.v-responsive__content {
display: flex;
flex-direction: column;
align-items: center;
// justify-content: center; // this will make everything vertical center
justify-content: space-between
}
.v-responsive__content > div {
width: 100%;
}
You can name space the class for any css conflict:
.my-card .v-responsive__content { ... }

You can use align-self on v-col ( align on v-row if you want put in seperate rows) for horizontal and offset on v-col for vertical
<v-row>
<v-col align-self="center" cols="6">
<v-card class="pa-3">align : start</v-card>
</v-col>
<v-col align-self="center" cols="6" offset="3">
<v-card class="pa-3 text-center">align : center</v-card>
</v-col>
<v-col align-self="end" cols="6" offset="6">
<v-card class="pa-3 text-end">align : end</v-card>
</v-col>
</v-row>
Here is the updated jsfiddle : https://jsfiddle.net/tunzLcw5/

Related

How to make cards have the same height?

My card hights is not displaying consistently as I intended. I was thinking to set the max-height to my v-card-text
<v-col cols="3" v-for="note in notes">
<v-card :loading="loading" max-width="374">
<template slot="progress">
<v-progress-linear color="deep-purple" height="10" indeterminate></v-progress-linear>
</template>
<v-img height="250" :src="note.img"></v-img>
<v-card-title>{{ note.name }}</v-card-title>
<v-card-text height="200px">
<div>{{ note.description }}</div>
</v-card-text>
<v-card-text>
<v-chip-group v-model="selection" active-class="deep-purple accent-4 white--text" column>
<v-chip v-for="tag in note.tag">
{{ tag }}
</v-chip>
</v-chip-group>
</v-card-text>
</v-card>
</v-col>
I see no effect
Any suggestions for me ?
You can achieve it with:
.v-card-text {
height: 200px;
overflow-y: auto;
}
If you don't want a scrollbar and you're fine with the text being cropped:
overflow-y: hidden;
Shortcomings:
.v-card-text will always have this height, even if all items on a row end up not using all of it
you might want to customise the scrollbar appearance on browsers which display a wide scrollbar (17px) on desktop (e.g: Chrome).
Alternatively, if you want the tallest card in each row to set the height (resulting in rows with cards of different heights) and not have any overflow, but have some white space on some cards instead, I can help you achieve it if you create a runnable snippet, so I can test. In principle, you need to give the card container display: flex; flex-direction: column; and give .v-card-text { flex-grow: 1 }.
In practice, the card might have more than one wrapper, which is why I need to see a live snippet, if you're interested in this solution.

How to prevent canvas from overflowing the card and make it responsive in vuetify?

Context:
Hi, I am trying to use fabricjs canvas within vuetify and make it look responsive in all the screens.
But currently, I am facing an issue where the canvas is not re-sizing based on card,it overflows the card instead.
I have tried using v-responsive but it does not apply the aspect ratio to canvas, could be, the way I am using it is not the right way.
Any suggestions will be helpful.
This is what is happening now
This is what i am trying to achieve
Structure
Mock:
Code
This is what i have tried till now.
<v-layout>
<v-flex xs12>
<v-container class="red" fluid>
<v-layout row wrap align-center justify-center>
<v-flex xs3 sm3 md3 class="ma-2" class="purple">
<v-card flat tile class="yellow">
<v-card-title
id="fabric-canvas-wrapper"
class="green pb-0 justify-center"
>
<v-responsive aspect-ratio="4/3" class="mx-auto px-3">
<canvas id="c"> </canvas>
</v-responsive>
</v-card-title>
<v-card-text class="blue text-xs-center py-0">
<p class=".body-2 pa-2 text-truncate">Kangaroo Valley Safari</p>
</v-card-text>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-flex>
</v-layout>
https://codepen.io/adatdeltax/pen/OJWOPBo
A canvas element can be sized arbitrarily by a style sheet, its bitmap is then subject to the 'object-fit' CSS property.
Source
The width/height of the canvas element are different from the width/height of the canvas element's bitmap. This means that you can use only CSS styles to fix this problem.
canvas {
width: 100%;
height: 100%;
object-fit: cover;
}
Example
If you want to maintain the aspect ratio you can use the padding trick.
.canvas-container {
width: 100%;
padding-top: 100%; // for 1:1 ratio
}
Example

How to make canvas responsive within vuetify card [duplicate]

Context:
Hi, I am trying to use fabricjs canvas within vuetify and make it look responsive in all the screens.
But currently, I am facing an issue where the canvas is not re-sizing based on card,it overflows the card instead.
I have tried using v-responsive but it does not apply the aspect ratio to canvas, could be, the way I am using it is not the right way.
Any suggestions will be helpful.
This is what is happening now
This is what i am trying to achieve
Structure
Mock:
Code
This is what i have tried till now.
<v-layout>
<v-flex xs12>
<v-container class="red" fluid>
<v-layout row wrap align-center justify-center>
<v-flex xs3 sm3 md3 class="ma-2" class="purple">
<v-card flat tile class="yellow">
<v-card-title
id="fabric-canvas-wrapper"
class="green pb-0 justify-center"
>
<v-responsive aspect-ratio="4/3" class="mx-auto px-3">
<canvas id="c"> </canvas>
</v-responsive>
</v-card-title>
<v-card-text class="blue text-xs-center py-0">
<p class=".body-2 pa-2 text-truncate">Kangaroo Valley Safari</p>
</v-card-text>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-flex>
</v-layout>
https://codepen.io/adatdeltax/pen/OJWOPBo
A canvas element can be sized arbitrarily by a style sheet, its bitmap is then subject to the 'object-fit' CSS property.
Source
The width/height of the canvas element are different from the width/height of the canvas element's bitmap. This means that you can use only CSS styles to fix this problem.
canvas {
width: 100%;
height: 100%;
object-fit: cover;
}
Example
If you want to maintain the aspect ratio you can use the padding trick.
.canvas-container {
width: 100%;
padding-top: 100%; // for 1:1 ratio
}
Example

Cannot remove scroll bar on Vuetify Navigation Drawer

I've moved my nav panel into a v-navigation-drawer. I want to remove the scrollbar as there is content I want to always be visible. I've tried the various tips but the scrollbar is still there. How can I hide or get rid of it?
<v-navigation-drawer
v-model="mainNavDrawer"
fixed
app
clipped
enable-resize-watcher
width="475"
class="pa-0"
mobile-break-point="1600"
><v-layout class="primary ma-0 pa-2 pt-1 d-xl-none">
<v-toolbar-title class="pa-1 white--text font-weight-bold"
>Knight Shop Invoice EasyPay</v-toolbar-title
>
<v-spacer></v-spacer>
<v-btn
x-small
class="mt-2 pa-3"
color="primary lighten-5"
dark
outlined
#click.stop="mainNavDrawer = !mainNavDrawer"
>
<v-icon dark left> mdi-arrow-left </v-icon>Close
</v-btn></v-layout
>
<v-container fluid class="py-0">
<v-row>
<v-col class="px-0 py-0" sm="12">
<v-container class="pt-0">
<v-row>
<v-col sm="12" class="px-2">
<TogglePOType />
</v-col>
</v-row>
<transition name="slide-fade">
<v-row v-show="this.selectedInvoiceStatus === 'needapproval'">
<v-col sm="12" class="py-0">
<RegionGraph :height="200" />
</v-col> </v-row
></transition>
<v-row>
<v-col sm="12" class="pa-0 pt-2">
<SelectVendors />
</v-col>
</v-row>
</v-container>
</v-col>
</v-row>
</v-container>
</v-navigation-drawer>
. . .
<style scoped>
.v-navigation-drawer__content {
height: 100%;
overflow-y: auto;
overflow-x: hidden;
}
</style>
I've tried applying overflow: hidden to the nav drawer and to each elment below but still no joy.
The proper class declaration that worked for me is
<style scoped>
v::deep .v-navigation-drawer__content {
overflow: hidden
}
</style>
Above is all I did
v::deep allows class to reach child components even with scoped property on
If you don't want to use v::deep, try removing the scoped property in your style tag
<style> <--- note without the scoped property
the scoped property prevent any class delcarations from reaching other components
In this case, since vuetify components are considered as separate component
scope tag will prevent your class delcaration take effect
Currently using vuetify 2.6.1
Note that the above works in removing scroll bar, but also disable user from scrolling with mouse wheel, so I resorted to method below.
<style scoped>
::v-deep ::-webkit-scrollbar {
width: 0
background: transparent
}
Doing this allows hiding of scroll bar while still enables scrolling
</style>
Please refer to here for detailed description on why.
Hide scroll bar, but while still being able to scroll
Try this! This is work for me.
.v-navigation-drawer__content::-webkit-scrollbar-track{
-webkit-box-shadow: inset 0 0 6px #5d5d5d;
background-color: #5d5d5d;
}
.v-navigation-drawer__content::-webkit-scrollbar{
width: 0px;
}
.v-navigation-drawer__content::-webkit-scrollbar-thumb{
-webkit-box-shadow: inset 0 0 6px #424242;
background-color: #424242;
}
Let me know if you can make it! :)
Do not use 'scoped' in your style tag.

Vuetify Two Images in Carousel-Item

All I want is to have a carousel-item that contains two images. At the very least I want two carousels side by side. Any ideas since wrapping the carousels in row-cols or simply trying a sheet containning two images in each carousel item does not work.
EDIT : Notice how the component surpasses the right edge of the app drawer (should not happen and also on transition the background of the carousel flashes black. Ideally I get a carousel that is responsive with the two images inside transitionning without flashing black.
<template>
<v-container>
<v-row>
<v-col cols="1">
<v-btn icon large #click="toggle">
<v-icon>{{ playIcon }}</v-icon>
</v-btn>
</v-col>
<v-col>
<v-slider
color="light-green"
thumb-color="light-green accent-4"
thumb-size="30"
track-color="light-green accent-4"
v-model="run"
max="19"
:tick-labels="ticksLabels"
tick-size="6"
ticks/>
</v-col>
</v-row>
<v-carousel
:cycle="playPause"
hide-delimiters
interval=3000
v-model="run"
height="700px"
hide-delimiter-background
show-arrows-on-hover
>
<v-carousel-item
transition="fade-transition"
reverse-transition="fade-transition"
v-for="(item,i) in items"
:key="i"
>
<v-row>
<v-card width="49%">
<v-img contain :src="item.avg"/>
</v-card>
<v-spacer></v-spacer>
<v-card width="49%">
<v-img contain :src="item.std"/>
</v-card>
</v-row>
</v-carousel-item>
</v-carousel>
</v-container>
</template>
You can fix the black flashing by adding these two props to the v-carousel
:dark="$vuetify.theme.dark"
:light="!$vuetify.theme.dark"
And to fix the scope of the component you can add this style.
<style scoped>
.v-carousel .v-window-item {
position: absolute;
top: 0;
width: 100%;
}
.v-carousel-item {
height: auto;
}
</style>