Enlarged image display featured in carousel viewing

I recently set up a carousel using Bootstrap 4, but I'm encountering a couple of issues that I need help with:

  1. The images in the carousel seem to be zoomed in when displayed. I'd like them to appear in their original sizes.

  2. How can I adjust the size of the entire carousel?

Below is the code snippet I've been working with:

html

<div class="carousel-inner">
    <div class="carousel-item active">
        <img src="/images/holz_40.jpg" class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
            <h1>lorem</h1>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam placeat esse dicta eos ex nobis, error, corrupti optio aspernatur debitis iure ut sapiente minima exercitationem inventore maiores explicabo natus vitae..</p>
        </div>
    </div>

css:

      .carousel {
        margin-bottom: 4rem;
        position: relative;    
      }       

      .carousel-caption {
        bottom: 3rem;
        z-index: 10;
      }

  .carousel-item {
    height: 32rem;
  }    

     .carousel-item > img {
        position: absolute;
        top: 0;
        left: 0;    
        height: 32rem;
        object-fit: cover;    
      }

If anyone could provide guidance on how to display the images in their original size and resize the carousel accordingly, it would be greatly appreciated!

Answer №1

One possible reason for the issue could be related to the object-fit:cover property in your .carousel-item > img rule.

According to the MDN documentation:

Cover: The replaced content is sized to maintain its aspect ratio while filling the element’s entire content box. If the object's aspect ratio does not match the aspect ratio of its box, then the object will be clipped to fit.

The cover property can be beneficial when developing for responsive designs, as it allows you to use images that work well with common aspect ratios.

If you wish to display the image in its original aspect ratio, you can change the property to 'contain', but ensure you adjust the dimensions of the carousel div accordingly.

.carousel {
        margin-bottom: 4rem;
        position: relative;   
        
      }       
      
      .carousel-inner {
        background: red;
      }

      .carousel-caption {
        bottom: 3rem;
        z-index: 10;
      }

  .carousel-item {
    height: 32rem;
  }    

     .carousel-item > img {
        position: absolute;
        top: 0;
        left: 0;    
        height: 32rem;
        object-fit: contain;    
      }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<dic class="carousel">
<div class="carousel-inner" >
    <div class="carousel-item active">
        <img src="https://interactive-examples.mdn.mozilla.net/media/examples/plumeria.jpg" class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
            <h1>lorem</h1>
            <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam placeat esse dicta eos ex nobis, error, corrupti optio aspernatur debitis iure ut sapiente minima exercitationem inventore maiores explicabo natus vitae..</p>
        </div>
    </div>
</div>

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

Model is disregarding media queries

Using LESS for CSS compilation, I have encountered an issue with the media query in my code. Specifically, I am attempting to apply different styles for mobile devices but they are not being rendered as expected. #main-wrap header #hdr-nav nav { width: ...

The Django Ajax Comment feature successfully updates and displays new comments, however, it seems to be unable to clear the content from

There was an issue with my comment form where the value wasn't being removed after submission. I had to refresh the page in order to comment again. I need assistance with this problem, specifically referring to the view function and Main JS part. Pl ...

Having trouble retrieving the date from the Bootstrap WTForm

I'm currently utilizing WTForm and bootstrap to collect the date input from a user. The page is loading correctly with the form to input a date, but when I click on a date and hit submit, the print(form.dmrDate.data) statement returns None. It seems ...

When the height of the window decreases, scrolling is not implemented

Having trouble adjusting the height of my Responsive Modal when the window height decreases. The content is slipping under the window and the scroll bar isn't adjusting accordingly. It seems like the nested div structure is causing issues. https://i.s ...

Creating a vertical navigation menu and displaying its submenu on corresponding pages in a horizontal layout

I'm struggling to design a navigation layout for my website where I want to display the main menu items like this: Menu 1 Menu 2 Menu 3 Menu 4 Menu 5 and have their respective sub-menus displayed horizontally on their main menu pages like this: ...

Interacting between client and server with the help of JavaScript and websockets

As someone new to Javascript, I am eager to learn about the steps and initial codes needed to establish a connection between the client side and the server side using JS and websockets. ...

Having trouble with Angular NgbModal beforeDismiss feature?

My goal is to add a class to the pop up modal before closing it, and then have it wait for a brief period before actually closing. I've been trying to do this using the beforeDismiss feature in the NgbModalOptions options in Angular Bootstrap's d ...

The issue of JQuery recursion not properly focusing on a textbox

Can anyone help with a jquery focus issue I'm experiencing? My goal is to address the placeholder problem in IE by focusing on an element and then blurring it to display the placeholder. This functionality is being used in a modal form. Initially, e ...

Enabling file input in Android's webview

Trying to create a web project using Android, utilizing WebView. There is an input field of type file <input type="file" > for users to upload files to the server. However, it appears that this feature does not work on Android WebView - when tapping ...

Error in displaying selected items list on Sidenav in 365 online platform

In our SharePoint site, we have a parent folder named 'Document' with subfolders '2017' and '2016'. We added these two subfolders to the side navigation bar. However, when selecting either '2016' or '2017' ...

Python tutorial: Executing onclick values with a click

I'm currently working on writing some Selenium Python code and I have a question. The website I am testing has multiple time slots available, and I am attempting to simulate a mouse click specifically geared towards the 8:30-11:30 timeslot. Below is ...

ReactJS is unable to locate a valid DOM element within the target container

I recently embarked on my journey to learn ReactJS and I celebrated successfully writing my first code. However, when I encountered the same pattern with components, an error popped up stating _Invariant Violation: registerComponent(...): Target container ...

Styling specific to Nuxt.js layout with scoped css

Currently, I am using Nuxt and have a header layout for my navigation that has a white background color. However, on a specific page, I would like to change the navigation background color to be transparent (only for this page). I have attempted a few so ...

How to center a div vertically in a window

I have a CSS layout that positions a div both horizontally and vertically relative to the window. It works well, but when I scroll down the page, the div stays centered as if the page hadn't moved. width:600px; height:300px; position:absolute; left:5 ...

Getting session data from a separate page tutorial in PHP

The current display only shows the user's email, while the phone number, city, and county are not being displayed. I would like to show all this information for a specific user. <?php session_start(); if(!($_SESSION['email'])){ hea ...

Utilizing pop-up info boxes

After thoroughly reviewing the documentation on Imagemapster's website and browsing several posts, I am still struggling to get the tooltips working correctly. I attempted to share my HTML and JS code on jsfiddle.com without success, so I have provide ...

Flexbox allows for the overflow of images within a container

Need help keeping my images from overflowing the <div class="display"> container and maintaining a square/box shape It should work with flexbox. Currently, the code displays 3 images with 1 extending outside the box, which is not the desired outcom ...

What is the best method for eliminating HTML line breaks <br />?

I have gathered a collection of reviews from web scraping, but unfortunately they are filled with unwanted <br \> tags. Even after cleaning the data by removing stopwords, I still find several lingering instances of the "br" tag in the dataset. ...

How can I pass a parameter to a selector for an Ajax call when onClick event

Utilize a JQUERY AJAX call within a $(document).ready(function()..) function that iterates over MongoDB documents and dynamically adds HTML Div elements to the page using a .get Each Div includes a <button type='button' id='deleteItem&ap ...

Steps for retrieving a JSON file from a web browser containing data in the JSON format

I need to download a text/json file using a string that contains the data in JSON format. In my controller, I am adding an ArrayList containing objects of the Service Class to the model. Here is the code snippet: @RequestMapping("/Application.html") p ...