Issue with SwiperJS not completely filling the height of a div

My issue relates to using swiperJS with multiple images, as I'm struggling to make it take the full width and height of the containing div. Despite applying styling like this to my images:

.swiper-slide img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

It seems that only the width is being considered, not the height.

I suspect that something within swiper is causing this resizing behavior, but the documentation only mentions autoHeight.

Here's how a snippet of my code looks:

const swiper = new Swiper('.swiper-container', {
            autoHeight: true,
            loop: true,
            effect: "fade",
            autoplay: {
              delay: 2500,
              disableOnInteraction: true,
            },
    
            pagination: {
              el: '.swiper-pagination',
              type: 'bullets',
            },
    
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev'
            }
          })
.container {
            max-width: 1100px;
            margin: 0 auto;
            padding: 10px 40px; 
        }
    
        .slider-wrapper {
            display: flex;
            margin-bottom: 50px;
        }
    
        .slider-container {
            width: 40%;
        }
    
        .swiper-container {
            width: 100%;
    
        }
    
        .swiper-slide img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
    
        .slider-content {
            width: 60%;
            padding-left: 40px;
        }
    
        .slider-content h3 {
            font-size: 1.8rem;
        }
    
        .slider-content p {
            font-weight: 200;
            margin: 20px 0;
        }
    
        .slider-content p:nth-of-type(3) {
            margin-bottom: 40px;
        }
    
        .slider-content strong {
            font-weight: 400;
        }
<!DOCTYPE html>
        <html lang="en">
          <head>
            <meta charset="UTF-8" />
            <meta http-equiv="X-UA-Compatible" content="IE=edge" />
            <meta name="viewport" content="width=device-width, initial-scale=1.0" />
            <link
              rel="stylesheet"
              href="https://unpkg.com/swiper/swiper-bundle.min.css"
            />
            <title>Document</title>
          </head>
          <body>
            <section id="slider">
              <div class="container">
                <div class="slider-wrapper">
                  <div class="slider-container">
                    <div class="swiper-container">
                      <div class="swiper-wrapper">
                        <div class="swiper-slide">
                          <img
                            src="https://images.unsplash.com/photo-1625523214628-4dec27885b68?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1951&q=80"
                            alt=""
                          />
                        </div>
                        <div class="swiper-slide">
                          <img
                            src="https://images.unsplash.com/photo-1625628748830-639e59adbcfc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1951&q=80"
                            alt=""
                          />
                        </div>
                      </div>
                      <div class="swiper-pagination"></div>
                      <div class="swiper-button-prev"></div>
                      <div class="swiper-button-next"></div>
                    </div>
                  </div>
  
                  <div class="slider-content">
                    <h3>
                      Lorem ipsum dolor sit amet consectetur adipisicing elit. Id,
                      cupiditate.
                    </h3>
                    <p>
                      Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit hic
                      consequuntur odio tempore? Saepe, tenetur suscipit perspiciatis
                      totam accusamus numquam pariatur nobis expedita in, neque,
                      veritatis deserunt reiciendis id excepturi?
                    </p>
                    <p>
                      Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit hic
                      consequuntur odio tempore? Saepe, tenetur suscipit perspiciatis
                      totam accusamus numquam pariatur nobis expedita in, neque,
                      veritatis deserunt reiciendis id excepturi?
                    </p>
    
                    <p>
                      Lorem ipsum, dolor sit amet consectetur adipisicing elit. Natus
                      quam ducimus accusantium possimus, nihil exercitationem temporibus
                      recusandae soluta quae voluptatibus.
                    </p>
                    <a class="btn" href="https://www.google.com">How it Works</a>
                  </div>
                </div>
              </div>
            </section>
            <script src="https://unpkg.com/swiper/swiper-bundle.js"></script>
            <script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
          </body>
        </html>

Answer №1

Success! This solution did the trick for my issue.

.swiper-slide{
    height: auto;
}

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

Experiencing an excessive number of re-renders can be a common issue in React as it has limitations set in place to prevent infinite loops. This

I have integrated React context to access the login function and error from the context provider file for logging into the firebase database. I am trying to display any thrown errors in the app during the login process. However, I encountered an issue whe ...

React app version displaying incorrect links to CSS and JS files

I have been immersed in a React project called Simple-portfolio, you can find the GitHub repository here: https://github.com/Devang47/simple-portfolio and the live site at this URL: While everything works smoothly on the development server, I encountered ...

An unforeseen issue arose while trying to update the data in a Chart.js chart within a Vue application

I am currently utilizing Chart.js version 3.5 along with Vue 3. After successfully creating a chart, I attempted to trigger a data change within a Vue method. However, I encountered an issue that displayed the following error message: "Uncaught TypeError: ...

"Triggering an event when a checkbox in a list is clicked

How can I add an onclick event to a checkbox within an <li> element, as shown in the picture? Here is my JavaScript code so far: It's not working. $(document).ready(function() { allFiles() /*----------------------------------------------- ...

Retrieve all default and user-defined fields associated with contacts in the CRM 2011 system

In CRM 2011, the contact entities come with a variety of default fields, and I have also included some custom fields. My goal is to retrieve all field names in a JavaScript list. When creating an email template in CRM, you can select fields from a dialog. ...

The conundrum with JQuery: My script refuses to run when a variable is defined

<script> $(document).foundation( let total = 1 $("button.test").click(function(){ if ($("p.change-me").text() === "OFF") { $("p.change-me").text("ON") total = total + 1 } ...

Is it possible to modify the object's key value when generating an array value with the map function in React?

I have the array object data stored in a variable called hi[0].child. hi[0].child = [ {code: "food", name: "burger"}, {code: "cloth", name: "outer"}, {code: "fruit", name: "apple"}, ] ...

Utilizing ES6 Map Reduce to flatten an array with mapping and padding, sourced from the Redux state

Currently, I am developing a React/Redux application using ES6 and looking for an efficient method to transform this dataset: [ {total: 50, label: "C1"}, {total: 120, label: "C2"}, {total: 220, label: "C4"} ] Into something similar to the structu ...

Tips for successfully sending an interface to a generic function

Is there a way to pass an interface as a type to a generic function? I anticipate that the generic function will be expanded in the future. Perhaps the current code is not suitable for my problem? This piece of code is being duplicated across multiple fil ...

What is the reason skip does not function properly at the start of the aggregation pipeline, yet performs as expected at the conclusion of it?

Initially, the skip stage in this MongoDB database aggregation framework pipeline isn't functioning as expected: [ { $skip: (!offset)? 0 :(offset-1)*limit }, { $match: (query)? query : {} } , { $lookup: ..., ...

Utilize titles and hrefs for images in an array of objects

In my Canvas, there is a map as the background image with markers placed in different cities. These markers are images duplicated from an Array of Objects and added to the Canvas using drawImage(). Now, I need to include href and title attributes in these ...

React - Error: you have a syntax problem because there is an unexpected token <

I am working on a project using Express, pg, and react. However, I have encountered some issues with React. Here is the directory of my project index.js var express = require('express'); var server = express(); var path = require('path&ap ...

Steps for changing an image with another image upon button click in Angular 6

I have a button with an image and text. When the button is clicked, I want to change both the image and content. Here's the code I'm currently using: <div class="btn-default"> <button name="Save" [ngClass]="[bntStyle]" (click)="submit ...

Tips for successfully passing multiple data IDs in a Bootstrap modal

Greetings! I am currently facing a challenge with passing multiple data IDs into a bootstrap modal. When I manually assign the data IDs, everything works perfectly: <a id="testB" href="#my_modal2" data-toggle="modal" data-book-id='{"id":10,"name ...

jQuery animation not executing as expected due to transition issues

I'm looking to create a cool effect where the previous quote disappears and a new one appears when I click on a button, all with a smooth transition effect. In my attempt below using jQuery .animate and opacity property, I'm struggling to make i ...

"Ensuring a mobile-friendly website menu's z-index is

I'm currently working on developing a responsive menu, but I've encountered some issues with setting the correct Z-index values. The problem arises when trying to add a "show menu" button that expands behind the main content (cwrap) after window ...

What is the best method to make the first input field the focus in BootStrap?

Is there a way to prioritize the focus on the initial input element in an HTML form without specifying an ID? How to set the focus to the first input element in an HTML form independent from the id? I'm working with BootStrap and ASP.NET MVC4. De ...

Is it possible to generate an array of objects, where each object includes an observable retrieved through forkJoin?

let food = { id: 1, isTasty: false } Imagine I have a custom function that takes the ID of a food item and returns an observable which resolves to a boolean indicating whether the food is tasty or not. I wish to loop through an array of food items an ...

Adaptive Table Layout that Creates a Page-breaking Design

I have a page layout with three columns: a fixed-width left-hand navigation, a responsive content column, and a fixed-width right-hand navigation. The issue arises when the content in the middle column includes HTML tables that sometimes exceed the availab ...

Adding a C# variable to a URL in a Razor view using jQuery

My Razor page looks like this: @{ ViewData["Title"] = "mypage"; string ApiAddress = "https://localhost:8114/api/"; } <div> ... </div> @section Scripts{ <script> functio ...