What is the method for adjusting the width of a v-card based on its height?

I have a changing number of v-cards that are displayed based on their quantity. My goal is to maintain an aspect ratio of 16/9, but only adjust the width.

To achieve this, I believe I need to make the width dependent on the height, although I am unsure how to accomplish this.

Here is what my code currently looks like:

<template>
<v-app >
    <v-main>
        <v-row v-for="i in numberOfRow" :key="i" align="center" justify="space-around" :style="'height:' + 100/numberOfRow + '%;'">
            <v-col 
                v-for="n in numberOfCol(i)" 
                :key="n" 
                style="display:flex; justify-content: center;align-content: center;"
            >
                <v-card
                    elevation="10"
                    :width="90 / numberOfCol(1) + 'vw'"
                    :height="90 / numberOfRow + 'vh'"
                    style="
                            display: flex;
                            flex-direction: row;
                            justify-content: center;
                        "
                >
                    <v-img 
                        src="https://i.redd.it/c3uhsgo1vx541.jpg" 
                        width="20%"
                        height="100%"
                        style="border-radius: 0 100% 100% 0%;"
                    />
                    <div style="width: 70%; height: 100%;">
                        <div style="width: 100%; height: 50%; display: flex;text-align: center; align-items: flex-end;">
                            <v-card-text class="text-h2 primary--text">Title</v-card-text>
                        </div>
                        <div style="width: 100%; height: 20%; text-align: center;">
                            <v-card-text class="text-body-2">This is the subtitle</v-card-text>
                        </div>
                    </div>
                </v-card>
            </v-col>
        </v-row>

    </v-main>
    <v-footer color="#005686" app bottom fixed padless>
        <span class="white--text"></span>
    </v-footer>
</v-app>
<script>export default {
name: "App",
components: {
},
data() {
    return {
        numberOfSection: 2
    };
},
computed: {
    numberOfRow() {
        if(this.numberOfSection%2 === 0) {
            return 2;
        }else if(this.numberOfSection%3 === 2) {
            return Math.floor(this.numberOfSection / 3) + 1;
        }else {
            return Math.floor(this.numberOfSection / 3) + this.numberOfSection%3;
        }
    }
},
methods: {
    numberOfCol( rowNumber) {
        if( this.numberOfSection%2 === 0) {
            return this.numberOfSection/2;
        }else{
            console.log(rowNumber === this.numberOfSection/3 ? this.numberOfSection%3 : 3);
            return rowNumber ===  Math.floor(this.numberOfSection / 3) + 1 ? this.numberOfSection%3 : 3;
        }
    }
} 

This is the current appearance:

https://i.stack.imgur.com/YMsv5.jpg

If anyone has suggestions on achieving this using CSS, Vue, or JS, please share!

Answer №1

Perhaps implementing font-size: clamp(MIN, VAL, MAX) in your style file could be the solution to your problem

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

The jQuery load() method may not load all elements

I've been struggling with a query issue for quite some time now. I have a Content Management System that I want to integrate into my website, but unfortunately, I am unable to use PHP includes. As an alternative, I decided to utilize jQuery instead. D ...

What is the best way to format the information when using response.send() in express.js?

I need help with customizing the content I'm returning in the app.post() method. Is there a way to do this? Below is an example of the app.post() code: app.post("/",function(req,res){ const query = req.body.cityName; const cityName = query.charA ...

Adjust the table to line up perfectly, center the content within the table cell (td), and align the

I'm currently working on aligning a table by centering the td elements and left justifying the text inside them. My initial attempt was to use flex for center alignment, which worked to some extent but I couldn't get the left alignment right. I ...

Resize the div blocks by scaling the button placed beneath them

I decided to modify the g-recaptcha widget to fit my specific requirements, and it is working flawlessly. However, I noticed that the ng-click button directly beneath it is no longer responsive. The reason behind this issue eludes me. Here is a snippet of ...

Processing images with PHP from an array using AJAX

I have designed a straightforward form for image uploading. I am storing the properties of the uploaded images in an array, and my goal is to send this array to a PHP file using ajax. However, when I attempt to access the uploaded image using $_FILES[&apos ...

Error in React .js: Unable to access property 'name' as it is undefined

I keep encountering this issue: Uncaught TypeError: Cannot read property 'name' of undefined In my code, I have a user object defined in the App.js file. However, when I attempt to access its properties within my Person component, it throws a ...

Do developers typically define all flux action types within a constants object as a common programming practice?

This question arises from an informative article on flux. The common approach involves defining all action types within a constants object and consistently referencing this object throughout the application. Why is it considered a common practice? What ...

What steps can be taken to disable Angular's automatic trimming of fields?

Is there a global way to prevent Angular from automatically trimming input fields throughout the entire application? I know that I can avoid it for specific fields using the ngTrim directive, but it's not ideal to add this directive to every text fiel ...

What is the best way to modify an array of objects within component state?

I am currently working on updating a specific property of an object that is stored in an array. Here's a glimpse of my current state: state = { todos: [ { id: '1', title: 'first item, completed: false }, { ...

What are the steps to implement the "render" function from one class into another class within three.js?

As a newcomer to three.js, I have been working on creating a bowling game. However, I am encountering an issue where I need to access a function from my "Application" class within the physics class that I have created. Here is a snippet of the Application ...

Keeping extensive files/information on disk in order to alleviate browser memory usage in JavaScript

Currently, I am faced with a challenge involving the encryption of very large files. Unfortunately, my browser keeps crashing due to running out of memory while trying to handle these massive files. To address this issue, I am considering transferring som ...

Issue: Vue TypeScript module not foundDescription: When using

Is there anyone out there who can assist me with this issue regarding my tsconfig.json file? { "compilerOptions": { "target": "esnext", "module": "esnext", "moduleResolution": " ...

Using VueJs to associate boolean values with dropdowns

I am currently working on a form with a dropdown menu containing two options: "True" and "False". My goal is to save the selected value as a boolean in the form. For instance, when the user selects "True", I want the value stored as true in boolean format ...

JavaScript and the Firefox Scratchpad platform

Currently, I am utilizing the MDN guide for learning JavaScript and experimenting with examples using scratchpad. Here's a scenario: console.log('The value of b is ' + b); var b; Why does the console log display "The value of b is -1"? I ...

The NextJS development server is frequently losing connection

Issue While working on my NextJS project, I've been experiencing occasional disruptions with my development server. Whenever I update my code, I encounter random occurrences of the dev server disconnecting and displaying the error message below: Type ...

Facing difficulty observing Content-Disposition header in create-react-app project

I am using a create-react-app that is being served by express. Express is acting as a proxy for the app and all the application logic resides in CRA. My issue lies in calling an API to download a file. The API sends back a "Content-Disposition" header wit ...

Running PHP scripts from JavaScript

Currently working on a PHP project that involves a dropdown select button in a webpage. The goal is to call a JavaScript function whenever the value of the dropdown changes, and then pass this selected value to retrieve additional details from a MySQL da ...

Using nuxt.js to populate a Vuetify table with data

I am encountering issues with fetching data into a vuetify table, as it is not displaying any data within the table. My Laravel API Route::get('/businesslist', 'BusinessController@userlist')->name('businesslist'); Larav ...

Tips for displaying real-time data and potentially selecting alternative options from the dropdown menu

Is there a way to display the currently selected option from a dropdown list, and then have the rest of the options appear when the list is expanded? Currently, my dropdown list only shows the available elements that I can choose from. HTML: < ...

Issue with a stationary directional light tracking the movement of a rotating object and/or changes in the camera perspective

I've been facing a challenge in implementing a day-night cycle with a directional light in an Earth model using custom shaders. Everything seems to work fine with the night and day maps, as well as the light, as long as I don't manipulate the cam ...