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

Encountering Vue linting errors related to the defineEmits function

I am encountering an issue with the linting of my Vue SPA. I am using the defineEmits function from the script setup syntactic sugar (https://v3.vuejs.org/api/sfc-script-setup.html). The error messages are perplexing, and I am seeking assistance on how to ...

Tips for updating the content within an HTML tag with jQuery

I am looking to update the parameter value of an applet tag based on the selection from a dropdown menu. As I am new to jQuery, I would appreciate any guidance on how to achieve this using jQuery. This is my current applet code: <applet id="decisiontr ...

The canvas's document.getElementById function is unable to find any matching element,

Hello everyone, I am currently diving into the world of javascript and trying to expand my knowledge. However, I have encountered a problem that has me stumped, and I could really use some assistance. While exploring, I came across this page: http://www.w ...

Step-by-step guide on redirecting to a different page following a successful POST API call using Jquery

I have the code below in my JavaScript file. $scope.addLookupAction = function () { $("#importForm").attr("action", 'xyz.com'); success:function(response) { $log.info("Redirecting to lookup home page"); ...

Comparing AngularJS and AppML

As a beginner in AngularJS and AppML, I am curious to understand the strengths and differences between these two frameworks. Despite some similarities I noticed on W3Schools, I'm eager to dive deeper into each one's unique features. ...

AngularJS Large file size

After successfully building the 5 MIN QUICKSTART app, I decided to minify it with webpack following the recommendations in the angularJS docs. To my surprise, the size of the minified AngularJS file turned out to be approximately 700 KB, which is significa ...

How can you use Vue.js @mouseover to target a specific <path> element within an <svg>?

Check out this Codepen example. I am working with an SVG map that contains various paths holding data. My goal is to retrieve the state name when hovering over a specific path. Currently, I have added an event listener to the svg element and am trying to ...

excess margin running along the left side of each page

When visiting http://tadris3.ir/, one may notice a peculiar space on the left side of all pages. Can anyone assist in resolving this bothersome issue? ...

Is it possible for the filter with the new date() function to accept formats other than yyyy-mm-dd?

After receiving a response from mydatepicker in the specific format below: { "isRange":false, "singleDate":{ "date":{ "year":2022, "month":5, "day":13 }, "jsDate": ...

What is the best way to manage data updates in my Vue component?

Is it possible to handle any part of my component's data changing in Vue, not just specific properties? For example, if I have: data() { return { myProp: false, myOtherProp: true } } I can create watches for each property individuall ...

Is it possible to scale images dynamically using CSS without losing their proper proportions?

http://jsfiddle.net/CJzCA/ Is there a way to resize images using CSS in the above jsfiddle? The keyboard images are currently too big compared to the text, and I usually solve this issue by using Photoshop. It would be more convenient if we could resize t ...

Steps to insert a new row for a grid item using material-ui

When it comes to breaking a line of grid item like this, the image shown below illustrates how the rest space of the grid should be empty. https://i.stack.imgur.com/pvSwo.png <Grid container spacing={3} <Grid item xs={12}> "Grid Item xs ...

Next.js - NextAuth consistently delivers a successful status code every time

In my Next.js project, I am utilizing NextAuth. The issue I'm encountering is that NextAuth consistently returns a 200 status code and updates the session to authenticated, even when the username or password doesn't match. I've attempted thr ...

Why won't Vanilla JavaScript work with my Rails application?

Having trouble implementing a full screen menu, no Rails errors but not working when project is run. Error received: Cannot read property 'addEventListener' of null JS code snippet: (function() { var Menu = (function() { var burger = d ...

Updating state with new data in React: A step-by-step guide

Recently, I delved into the world of reactjs and embarked on a journey to fetch data from an API: constructor(){ super(); this.state = {data: false} this.nextProps ={}; axios.get('https://jsonplaceholder.typicode.com/posts') ...

`The process of adding an element to the beginning of an array``

I find myself in this scenario: I am dealing with 2 array1 variables, defined as array1 = ["fruit","vegetables"]; and array2 = [["apple","banana"],["tomato"]]; // index 0:represent fruit i,e (["apple","banana"]), index 1: vegetables i,e (["tomato"]) T ...

Utilizing Javascript to filter data across multiple columns in tables

I've been experimenting with the JavaScript code below to filter table rows. The original code is from w3schools, but I made some modifications to target all input values. It works well for filtering one column, however, when I try to input a value in ...

The alignment of Material-UI Button and ButtonGroup is not consistent

I'm puzzled as to why the Button and ButtonGroup elements are not aligned on the baseline in the code snippet provided. Is there a specific property that can be adjusted on the ButtonGroup element to achieve alignment? <!DOCTYPE html> <htm ...

Using JQUERY to store the ID of a div along with its checked value in a multidimensional array

I am looking to create an array that stores the ID of a div and the checked value. Check out this FIDDLE for reference For example, if I check samsung and lenovo under brands, and select 4gb for RAM, the array should be: array[ ] = ["brands" ...

I am looking to retrieve data from the Graph API JSON and gradually refine my search to achieve successful

I am looking to retrieve data from the "fb_page_categories" endpoint, which provides an array of categories a page can be categorized under. The format for this request is as follows: GET graph.facebook.com /fb_page_categories? Once this request is mad ...