The last image in the Bootstrap 4 carousel maintains a wider width than the slider itself, not resizing to fit within the slider during animations when the screen is adjusted

Check out my Bootstrap 4 carousel slider on this link.

The slider consists of 3 slides, but for optimal page speed performance, I've included 5 images of different sizes that load at specific screen widths. This was achieved using the <picture> and <srcset> elements.

Take a look at the code snippet below:

<div class="carousel-item">
 <picture>
    <source class="lazy" srcset="img/carousel/great-wall44-375.jpg" media="(max-width: 375px)" >
    <source class="lazy" srcset="img/carousel/great-wall44-768.jpg" media="(max-width: 768px)" >
    <source class="lazy" srcset="img/carousel/great-wall44-1200x514.jpg" media="(max-width: 1200px)" >
    <source class="lazy" srcset="img/carousel/great-wall44-1400x514.jpg" media="(max-width: 1400px)" >  
    <source class="lazy" srcset="img/carousel/great-wall44-1920x902-low.jpg" media="(max-width: 1920px)" >
    <img class="lazy" src="img/carousel/great-wall44.jpg" data-src="img/carousel/great-wall44-new5.jpg" >
 </picture>
</div>

The images are set to load at their respective breakpoints: 375px, 768px, 1200px, 1400px, and 1920px. The functionality works flawlessly up until..

The Issue

Upon resizing the page (or viewing on a small device), the first 2 slides transition smoothly, while the final slide appears to initially expand to the full width of the image before returning to the beginning of the slideshow.

To illustrate this problem further, refer to the examples provided:

  1. Visit this site.
  2. Resize the browser to 400px. You'll notice that a 768px image is loaded within a 375px - 767px screen width range in the slider. View the image below for reference:

    https://i.sstatic.net/hnGma.png

  3. The first 2 slides function smoothly. Good job!

  4. Here's what the 3rd Slide looks like at 400px screen width:

    https://i.sstatic.net/zvlmA.png

  5. An illustration of the 768px image displayed within the 400px slide div.

    https://i.sstatic.net/HHvii.jpg

  6. As it transitions, instead of sliding with the cropped image at 400px, it expands all the way to the full 768px image before returning to the start, resulting in an awkward animation:

    https://i.sstatic.net/8ak7R.png

This behavior occurs at each breakpoint during the process.

This jarring effect is undesirable. I am seeking assistance to address this issue. Please review the slider and replicate the steps to observe the problem firsthand.

Your help is greatly appreciated,

Thank you in advance.

Answer №1

After some troubleshooting, I managed to fix the issue with the carousel image not cropping to the slider width. The solution was to include overflow: hidden; in the .carousel-item class.

Although the HTML remains unchanged, the CSS has been updated:

.carousel-item {
      overflow: hidden;
}

Excellent news! Hopefully, this resolution will be beneficial for those encountering problems with bootstrap carousels and slider image overflow.

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

Aligning inline form controls with Bootstrap and Syncfusion widgets

I'm facing a challenge aligning the Syncfusion JavaScript widget - a dropdownlist - to be displayed inline with the label. I am using Bootstrap 3. I haven't been successful in achieving a nice alignment, meaning getting the middle of the label p ...

Troubleshoot: Dropdown menu in Materialize not functioning (menu fails to drop down

I am currently incorporating Materialize to create a dropdown button in my navigation bar. However, I am facing an issue where nothing happens when the button is clicked. Here is a snippet of my code: <head> <meta charset="UTF-8"> <!-- ...

Is it feasible to utilize Sublime Editor for building SCSS/SASS files? Learn how to compile SCSS/SASS with Sublime Editor

Despite numerous attempts, I have been unable to figure out how to effectively use the Sublime Editor for creating scss/sass files. ...

Is there a way to ensure my React navigation screen fills the entire screen?

I am currently facing an issue where my map screen is not covering the whole screen, leaving a blank space at the bottom where the custom bottom navigator should be displayed. How can I adjust my code so that the map covers this blank space at the bottom? ...

Issues with connecting local CSS and JS files to HTML pages

I am facing an issue with my base HTML file that I want all other pages to inherit certain characteristics from. The problem arises when I try to link an external CSS file like bootstrap.css from within my project directory. I have the file stored in the s ...

Using CSS to create a transition effect for fading in and out background images

I created a website with a captivating full-page background image (img/bg_start.jpg): If you hover your mouse over the central animal on the page, the current image (img/bg_start.jpg) will fade out and be replaced with another picture (img/bg_start2.jpg) ...

Switch the Bootstrap navigation bar orientation from left to right

Can anyone help me create a navigation bar like the one shown in this image? It needs to toggle from right to left with a close button. I've tried everything and searched everywhere with no luck. Thanks in advance! Link to Image ...

Is there a way to modify the FixedTableHeader jQuery plugin to include a fixed first column in addition to the fixed header?

I've been experimenting with a jQuery plugin I found at to create a stylish table with fixed headers, sorting options, and other interesting features. While the plugin is great, I also considered using jqGrid for its impressive capabilities. However, ...

Steps to create a hover effect similar to that of a website (increasing grid size on hover)

Looking to create a hover effect for my boxes similar to the one on this website: I've examined the code of the website above and searched extensively for a similar feature without any luck. Could anyone offer assistance with this, please? ...

Troubleshooting the issue with the simple Angular material layout/flex example

I attempted to implement a basic layout/flex example from the Angular material design demo site: https://material.angularjs.org/latest/layout/container However, no matter what I try, the layout does not function as described and simply arranges the four ...

Eliminating `<style>` tags within the `<head>` section

Our software system is generating unnecessary <style> tags within the <head> section. These tags are not required and need to be removed. I attempted to remove them using the following approach, but it seems that my logic may have some flaws. ...

Steps to resolve the 'Unknown keyword' issue while packaging a CSS file using webpack

In the process of upgrading dependencies to the latest versions for my Electron app built in Angular, I have encountered some issues. ✅ Electron remains on v19 ✅ Tailwindcss is updated to v3.1.8 ⬆️ Angular is being upgraded from v11 to v14 ⬆️ ...

What is the best way to set a single column to have a fixed position when scrolling horizontally?

There is an inline form that extends both horizontally and vertically. Within this form, there is a final column containing an add button which I would like to have a fixed position only when scrolling horizontally, not vertically. <!doctype html> &l ...

How do I use CSS to organize data by row and column within a table?

I'm looking to format the table data in a column-row layout for mobile devices. Can anyone provide an example or guidance on how to achieve this? I've browsed through some discussions but haven't found a solution that works with tables. The ...

Comparison between Mobile Phone's innerWidth and innerHeight Versus Resolution

My test phone, the Galaxy S3 Mini, has a resolution of 800x480 according to its specs. Strangely, when I run the following code in my HTML game: window.innerWidth window.innerHeight The width appears as 533 and the height as 295. I recently discovered ...

Change the width of a div element without causing text to wrap when resizing the browser window

Looking to create a layout with three div elements, each containing an h1 element. The goal is to have the first div on the left side, the second div in the center, and the third div on the right side, all in a single row. When the window is resized for re ...

Is there a bug with the CSS Safari selector for elements focused together?

Looking for a solution using the element+element-Selector to modify CSS for an element following a button. This code snippet functions in Chrome, Edge, and Firefox but not Safari on MacOS: .button:focus+.change{ color: red; } <p>When you focus ...

What is the best way to create a sliding menu that appears from the right side on a mobile device using HTML, CSS, and JQuery

Is there a way to have the menu slide in smoothly from the right side after clicking on the menu bar icon, including sliding the menu bar icon itself? The current code displays the menu directly upon clicking on the menu bar, but I would like it to slide i ...

What is the best way to create a layout for Flexbox project boxes with three boxes per row?

My project cards are displaying in a single horizontal line and expanding infinitely to the right, rather than appearing in rows of three as intended. This causes them to extend outside the visible area in a long horizontal strip. See the issue in action ...

What is the best way to display just the border of a background image while hiding the content?

The demonstration at this codepen https://codepen.io/Chester/pen/QPoyjN showcases a border animation effect. While it works effectively with a white background, I am interested in making the box's background dynamic. <div class="rainbow"& ...