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

How can I fetch data from a ManyToMany jointable using Typeorm?

Is there a way to retrieve the categories associated with posts when fetching user data? Data Models: @Entity() export class Category extends BaseEntity { @PrimaryGeneratedColumn() id: string; @Column() name: string; @Column() description: s ...

Adjust the color of each list item depending on an array of strings

Within my perspective, I possess a collection of different statuses. <ul> <li>FIRST_STATUS</li> <li>SECOND_STATUS</li> <li>THIRD_STATUS</li> </ul> To continuously update the statuses in my contr ...

Sending parameters with $location.path() in AngularJS

Having trouble creating a redirection call in the controller with a numerical parameter. Here is the code I've been using: $location.path('/tasklist/:$rootScope.job_id'); I have also attempted the following: $location.path("/tasklist/",$r ...

Tips for retrieving multiple data outputs from an ajax success function

Within my project, I have two separate JavaScript files named myJs1.js and myJs2.js. One of the methods in myJs1.js is invoking a method from myJs2.js. My goal is to retrieve the values r1 and r2 into the results (within myJs1.js). I attempted to achiev ...

Extract information from a database table for presentation as simple text

I am looking to extract information from each row and display it as plain text on the same page within a paragraph. Here is an example table for reference: <table> <thead> <tr> <th class="a header">A</th ...

Having difficulty assigning a JSON key value to a variable

I am encountering an issue where I keep receiving '[object HTMLParagraphElement]' instead of the ID value that I expected. The desired output should resemble this: I attempted to store the console.log output in a variable, but my attempts were ...

Passing PHP value from a current page to a popup page externally: A guide

I'm currently facing an issue at work where there is a repetitive button and value based on the database. I need to extract the selected value from the current page into a pop-up page whenever the corresponding button is clicked throughout the repetit ...

Next.js components do not alter the attributes of the div element

I am encountering a problem with nextjs/reactjs. I have two tsx files: index.tsx and customAlert.tsx. The issue that I am facing is that the alert does not change color even though the CSS classes are being added to the alert HTML element. Tailwind is my c ...

Is there a glitch in Safari's CSS involving max-height?

Currently, I am in the process of developing a popup for a registration form. The CSS rules have been configured accordingly and after testing on various browsers, it has come to my attention that Safari is displaying an additional white space between elem ...

What's the Hold-Up with IntersectionObserver in Brackets?

As a novice in the world of web development, I have been utilizing Brackets as my main tool. Recently, I've encountered a few hurdles specifically related to javascript. One issue I'm facing is trying to implement lazy loading on a div containing ...

Working with AngularJS's $q promise and socket.io

I am interested in creating an angularJS promise that can work seamlessly with socket.io. Currently, I have a callback function set up to handle the response like this: function request(event, data, callback) { socket.emit(event, data); socket.on( ...

I keep encountering an attach() error every time I try to close a modal that contains a vee-validated form

Every time I try to close a bootstrap modal (using bootstrap-vue) that includes a vee-validated "update" form with vue.js, I encounter the following error: main.js:477686 Uncaught (in promise) Error: [vee-validate] Validating a non-existent field: "#35". ...

Sorting files in jquery file upload

Has anyone had experience using the jQuery-File-Upload library from https://github.com/blueimp/jQuery-File-Upload? I'm currently facing an issue and wondering if anyone could assist me in sorting the files in a different manner. By default, this scrip ...

Difficulty encountered while attempting to deploy the front-end on Heroku

I recently completed a typeorm project with the following structure: https://i.stack.imgur.com/ReQK1.png Both the client and root directories contain index files located in the src directory. In the package.json file within the client directory, I made a ...

What is the best way to make an HTML table with a static header and a scrollable body?

Is there a way to keep the table header fixed while allowing the table body to scroll in an HTML table? Any advice on how to achieve this would be greatly appreciated. Thanks in advance! ...

Modify the text in a paragraph by clicking on a link using JQuery and HTML

I'm attempting to implement a straightforward action, but I'm facing some challenges. My navigation bar consists of a few links followed by a text section. What I aim for is that when I click on a link, the paragraph of text should change to refl ...

Using JavaScript, create a set of buttons within a div element and implement

$(document).ready(function() { $('#b1').click(function() { $('#uch').toggle("slow"); }); $('#b2').click(function() { $('#uch2').toggle("slow"); }) }) Although I'm not a program ...

What is the process for activating and deactivating the scroll trigger within Material UI's useScrollTrigger module?

I'm currently working on setting up a survey page with Material UI in React. My goal is to have the survey questions appear when the user scrolls over them and disappear when they scroll out of view, similar to the behavior on this page. After some r ...

Is there a way for me to receive a success message when I successfully set data in Firebase?

I want to retrieve the orderId after successfully adding an order to the Realtime database using angularfirestore. What should I use after set() method to return the orderId? The structure of my order object is as follows: const orderObj: Order = { pay ...

Using Google App Script for Slides to center-align text within a text box

Currently, I am tackling a project that demands the center alignment of text within a textbox on a google slide using a google app script. The primary objective is to fetch text from a google worksheet and an image from google drive. Subsequently, combine ...