What's the best way to vertically center a <p> element inside a Vuetify v-card?

The code displayed below showcases the structure of a container with various elements inside:

<v-container fluid>
    <!-- page title -->
    <v-row>
      …
    </v-row>
    <!-- body -->
    <v-row justify="center" no-gutters>
      <!-- input -->
      <v-col cols="5">
        <v-card outlined height="80vh" max-height="80vh" class="pa-8">
          <!-- image upload -->
          <v-row>
            <v-col>
              <v-file-input
                accept="image/png, image/jpeg"
                chips
                label="Choose an image(JPG or PNG)"
                outlined
                prepend-icon="image"
                show-size
                v-model="image"
                @change="previewImage"
                @click:clear="clearAll"
              ></v-file-input>
            </v-col>
          </v-row>
          <!-- image preview -->
          <v-row>
            <v-col>
              <p v-if="no_image" class="text-center text-h4 grey--text">
                Image Preview
              </p>
              <v-img v-else :src="imageUrl" contain max-height="55vh"></v-img>
            </v-col>
          </v-row>
        </v-card>
      </v-col>
      <!-- button -->
      <v-col align-self="center" cols="2">
        …
      </v-col>
      <!-- output -->
      <v-col cols="5" align-self="center">
        …
      </v-col>
    </v-row>
  </v-container>

This is just a markup example, and the current style can be viewed https://i.sstatic.net/pk6m7.png.

However, it seems that there is an issue with centering the "Image Preview" text vertically within the v-card element. Various attempts to use properties like align="center", class="align-center", align-self="center" on different elements have proven unsuccessful so far.
What would be the appropriate solution for achieving this layout?

Answer №1

To perfectly center the second div vertically, use the following code snippet.

<template>
  <v-container fluid>
    <v-row>
    </v-row>
    <v-row justify="center" no-gutters>
      <v-col cols="5">
        <v-card outlined height="80vh" max-height="80vh" class="pa-8 d-flex flex-column">
          <v-row class="flex-grow-0">
            <v-col>
              <v-file-input accept="image/png, image/jpeg" chips label="Choose an image(JPG or PNG)" outlined
                prepend-icon="image">
              </v-file-input>
            </v-col>
          </v-row>
          <v-row>
            <v-col class="d-flex flex-column justify-center">
              <p class="text-center text-h4 grey--text">
                Image Preview
              </p>
            </v-col>
          </v-row>
        </v-card>
      </v-col>
      <v-col align-self="center" cols="2">
      </v-col>
      <v-col cols="5" align-self="center">
      </v-col>
    </v-row>
  </v-container>
</template>

Here is how it will appear:

https://i.sstatic.net/qOAv3.jpg

The extra space below the content is due to this element:

https://i.sstatic.net/TQnan.png


Check out this concise and helpful flexbox cheatsheet: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Answer №2

Implement the display flex attribute:

display: flex;
align-items: center;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loading modules conditionally in Nuxt.js

In my Nuxt.js configuration, I have included a module for Google Tag Manager like this: modules: [ [ '@nuxtjs/google-tag-manager', { id: 'GTM-XXXXXXX' } ] ] Everything is functioning properly, but I am curious ab ...

Trouble with Implementing Nested h3 Styles in SCSS

I'm having trouble adjusting the margins of an h3 tag using scss in Angular. The scss code seems to be working, but when I nest the h3 tag inside a div tag, the margin adjustments don't take effect. Could someone help me figure out what's g ...

Using Bootstrap 3's hidden-xs class can help slim down the width of

I am currently testing out the Bootstrap 3 responsive grids and attempting to hide a column from a row when the screen size is small. However, I find that when the column disappears, the entire row seems to shrink in width. Here's the code causing me ...

Tips on adjusting the text color of the material radio button

Looking for some assistance here. I'm working with a small piece of code that combines Material UI and Angular. I have a radio button group where the text color is not changing, despite setting the SCSS value to #262D34. <mat-radio-group aria-label ...

Integrates an interactive feature within the select tag (<select>)

I'm struggling with creating a drop-down menu using the <select> element. My goal is to have a question mark (?) displayed next to each option in the menu, which will provide a brief explanation when hovered over. You can see an example of what ...

Can setTimeout be used to create a repeating animation loop?

Currently, I am in the process of creating a slider from scratch. Although there are ready-made plugins available for this purpose, my goal is to understand the underlying logic by building it myself. So far, I have managed to piece together most of the co ...

Ways to insert a gap underneath every line

Hello, I'm struggling to create space below each line of code. I've tried using the br tag and margin property, but it didn't work. Can anyone help me with this? I'm not sure if the current HTML structure is correct or if I should swit ...

Top destination for verifying permissions in vue.js

Within my Laravel/vue.js application, the initial page load results in a structure like this: <script> window.settings = {}; window.settings.user = {}; window.settings.user.timezone = 'Europe/Moscow'; w ...

Play a matching game using CSS3 to match and check tiles

Currently in the process of creating a game using HTML5 and CSS3. I'm working with several divs that have hover-activated CSS3 animations. The game itself is a simple matching tiles/cars game, optimized for Chrome as it currently only supports -webki ...

Enlarge an element to the extent of filling the list item

I am facing a challenge in expanding the a elements within this jsfiddle to fully occupy the li element. The use of display:block does not seem to be effective since I am utilizing a table for spacing. What steps can I take to achieve this while ensuring ...

SVG Height remains fixed despite aspect ratio adjustments

Using one SVG image in a div with a width of 50px results in a height of 150px in IE11. The correct dimensions should be 50px x 50px. The width is applied correctly, but the height is not. Any suggestions? .svg-cont{ width:50px } img{ max-width:100% ...

Setting row heights based on text in a chosen column within Excel

Hey there, I'm currently using Java code to generate a report in Excel. I've managed to set the height of rows and width of columns, but I've run into an issue where some data in a column is too large and affecting the height of other column ...

Navigating within fixed-positioned divs

I'm attempting to create something similar to the layout seen on: The desired effect is to have fixed content on the right side, with only the left side scrolling up to a certain point before the entire page scrolls normally. However, in my implement ...

Is there a way to efficiently create an ng-repeat for multiple divs?

I am looking to iterate through a collection of divs, as mentioned below. Each object in the list will have content-data and a link to an image. The code provided shows individual entries for each list item, but I would like to retrieve it from the angular ...

Adjust input width based on content in VueJS

Is it possible to achieve the following using (Pug & CoffeeScript): input(placeholder="0", v-model.number="order[index]" v-on:change="adjustInput") ... adjustInput: -> event.target.style.width = event.target.value.length + 'ch' Even ...

"Struggling to divide CSS Code with PHP containing nested brackets? Here's how you can tackle it

I'm currently attempting to break down my CSS code stored in variables, but I consistently encounter issues when dealing with media queries or similar elements. While I don't require every single rule to be outlined, I am looking for a solution ...

CSS: Automatically resize all divs to match the height of the tallest div when content is added

My component consists of divs with text inside, utilizing the overflow-wrap: break-word property to ensure the text fits correctly. As seen in this image on PC screens: example However, when I decrease the screen width, some words break and only certain d ...

Achieving full table height with a parent having a min-height requirement

Encountering a seemingly straightforward issue where I am unable to make an inner div 100% height of the parent div, which is set with min-height 70vh. My goal is to have the table inside be 100% height and content vertically aligned. It currently works if ...

Is there a way to determine if a container is overflowing at the top?

Currently, I am using Puppeteer to scrape Slack. My goal is to confirm whether I have scrolled to the very top of the channel feed. The issue arises because the channel feed does not actually scroll, making it impossible for me to utilize the method outli ...

Including HTML in a Prop for Nuxt

I have a question about passing HTML content inside a Prop in order to display an SVG logo. projectSVGLogo: { type: String, required: false } When I try accessing it like this <TheCarouselProjects projectPath="/tmbc" projectImg="image-test" ...