Properly positioning images within a v-carousel module

In my v-carousel, I have set a height of 40vh. The images inside the carousel are of different sizes, and I want to ensure that none of them get cut off. To achieve this, I used "contain" for the v-image along with a maximum height matching the carousel container.

However, I am facing an issue where some of the more "landscape" style images are positioned at the top of the carousel container. I would like all images to align to the center, similar to how the carousel default justifies all images to the center. I tried accessing the v-img through CSS and setting the image to align-center on the grid, but it doesn't seem to be working. I am able to confirm that I am accessing the img element because when I use display:none within the CSS class, it works.

Is there a way to align the images inside the carousel?

<div id="carousel-container">
        <v-carousel 
            height="40vh"
            show-arrows-on-hover 
            cycle
            >
            <v-carousel-item class="mob-one-carousel-item" v-for="(item,i) in items" :key="i">
                <v-img class="mob-one-carousel-img" :src="item.src" contain max-height="40vh"></v-img>
            </v-carousel-item>
    </v-carousel>
</div>

The following CSS grid code is not achieving the desired alignment:

.mob-one-carousel-item {
   display: grid;

   .mob-one-carousel-img {
       align-self: center;
   }
}

Answer №1

Here is the solution I found:

To make it work, I decided to wrap the image in another div that would take up 100% of the height of the v-carousel-item. This new div was then styled using grid properties to align and justify the images properly.

Additionally, I made sure to set the height of the image itself to automatically adjust based on its content.

<v-carousel-item class="mob-carousel-item" v-for="(item,i) in items" :key="i">
                <div class="mob-carousel-img-container">
                    <v-img class="mob-carousel-img" :src="item.src" contain max-height="40vh"></v-img>
                </div>
            </v-carousel-item>
.mob-carousel-item {

            .mob-carousel-img-container {
                height: 100%;
                width: 100%;
                display: grid;
                justify-items: center;
                align-items: center;
                .mob-carousel-img {
                    align-self: center;
                    height: auto;
                    max-height: 100%;
                }
            }
        }

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

Combining Django, Graphene, Apollo, django-webpack-loader, and Vue: Struggling with CORS and CSRF compatibility issues?

Currently, I am immersed in a project that involves Django as the backend, Vue as the frontend, and Apollo/Graphene/GraphQL as the data transfer layer. While most of it is functioning smoothly, I am encountering difficulties with the CORS/CSRF settings. I ...

Incorporate a new JavaScript animation as the background for an established website, replacing the static background image

Seeking assistance with my portfolio as I delve into the world of Webdesign and learn the basics from templates. How can I integrate this javascript code into the background of my site, replacing the current minecraft image? Every attempt to implement it ...

Vue: Accessing my initial data value as a function parameter is causing accessibility issues

Whenever I attempt to trigger the click handler in my button, an error is thrown stating TypeError: Cannot read property 'discountProduct' of null. Despite confirming that this.discountProduct.id does have a value through Vue Tools inspection and ...

Running a function following the completion of an animation with setTimeout

Recently stumbled upon this cool code snippet on stack overflow http://codepen.io/anon/pen/LERrGG. I see a lot of potential in this pen, but the one drawback is the lack of functionality to execute a function after the timer expires. I've been trying ...

How can I create a v-slot template with dynamic content in Vue.js?

Hello there! I appreciate you taking the time to read my inquiry. Currently, I am delving into Vue.js, Vuetify, and v-data-table for a project. I am faced with a challenge of getting my v-slot to function with two different strings as the header name. < ...

Transfer the Vue query parameter from the current route to the router-link

Why is it so challenging to detect and pass query parameters in Vue components? I'm trying to access the router from my component, but nothing seems to be working. How can I achieve this? <router-link :to="{ path: '/', query: { myQue ...

Tips for adding a space before the footer in a document

Implementing a Top Navigation Bar with grey spacing Avoid having any extra space just before the footer: Organizing my Layout File ("navigation_top" refers to the black navigation bar at the top) %body = render "navigation_top" .main-content .cont ...

Transform a Static Page into an Interactive Design

As a novice in web design, I have created a page using HTML and CSS. Now, I am looking to make my static page responsive, so that the styling remains consistent when the browser window is resized. Below are the dimensions of my body: body{ width:100%; ...

My CSS is giving me a bit of trouble with alignment

I have been experimenting with various approaches such as adjusting the size of the divs to tiny dimensions and trying out inline-block or float left and right properties, but I am still unable to achieve the desired result of having my divs positioned s ...

What is the best method for creating a pop-up image with CSS3?

Hey there, I've been struggling to create a pop-up image effect using CSS and CSS3. Unfortunately, I'm facing some issues with pseudo-classes like (visited, actived, and focus) as they don't seem to work for me. The only one that works is ho ...

How to achieve inter-column padding in Bootstrap 4 while eliminating the need for side margins

I'm currently working with Bootstrap 4.1 and I have a grid layout consisting of cells (Box A-E) with some space between them. The issue I'm facing is that when I apply padding to each column, it also adds padding to the left and right sides, caus ...

Animated Gradient Header with CSS

I've been attempting to add an animated gradient to my header class, but so far I haven't been successful. I want the gradient to apply only to the header, not the body. Here's the link I'm using for reference: Can anyone offer some i ...

Issues with Font Awesome fonts failing to load after compiling an Angular project using `ng build`

I've encountered an issue with Angular 8 and Font Awesome icons. I initially added the font-awesome path in the angular.json as follows: "./node_modules/font-awesome/css/font-awesome.css" However, all the icons were displaying as empty boxes (not lo ...

CSS Layout - Float: What's floating to the top?

Are there any CSS techniques available to make floated blocks fill in both upwards and in their float direction? For example - https://i.sstatic.net/uo06B.png Instead of - https://i.sstatic.net/oEijA.png I know this can be achieved using JavaScript li ...

Tips on showing a stub component in Vue when the original component is not found

Seeking a way to handle the scenario where a component is not found, such as: { template: '<some-unknown-component></some-unknown-component>' } When this happens, Vue issues a warning: unknown custom element: <some-unknown-comp ...

Discover the secret to instantly displaying comments after submission without refreshing the page in VueJS

Is there a way to display the comment instantly after clicking on the submit button, without having to refresh the page? Currently, the comment is saved to the database but only appears after refreshing. I'm looking for a solution or syntax that can h ...

What is the best way to enable horizontal scrolling for textarea overflow in a smooth manner like input, without any sudden jumps?

Currently, I am interested in utilizing a one-line textarea (with rows=1 and overflow-x:hidden;) similar to input type="text. However, I have encountered an issue where the content scrolls with "jumps" while typing inside it: https://i.stack.imgur.com/Rzf ...

Displaying a profile hover card allows users to easily discover and choose whether to follow or explore

I created a profile hover card on my website with a follow/unfollow button. However, I encountered an issue - the hover card disappears when I move away from my profile thumbnail. How can I fix this so that the hover card stays visible on mouseover and dis ...

Issue with vueform/multiselect component when used as a single file component

I've been encountering some unusual errors while attempting to integrate vueform/multiselect. Most of the examples I've come across don't make use of single-file components, but that's the method I prefer. My goal is to import the Multi ...

"Fixing VueJS axios issue: receiving 401 error for unauthorized POST request

I am having trouble sending a POST request with authorization to my REST api. Despite having CORS enabled on the server and everything working fine in Postman, I keep receiving an "unauthorized" error. Here is the code snippet I am using: axios . ...