Troubleshooting issue with Bootstrap 4 carousel displaying images with overlay

I'm currently working on creating a carousel with 3 background images. The issue I'm facing is that only the first image appears when the carousel slides, while the rest do not display properly - instead, the background color of the slider shows up.

I want all the background images to be visible as intended.

Thank you!

HTML CODE

 <div class="slider">
    <div id="main-slider" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
            <li data-target="#main-slider" data-slide-to="0" class="active"></li>
            <li data-target="#main-slider" data-slide-to="1"></li>
            <li data-target="#main-slider" data-slide-to="2"></li>
        </ol>
        <div class="carousel-inner">
            <h1>We are an independent <br>design and <span>development</span><br> agency.</h1>
            <div class="overlay"></div>
            <div class="carousel-item active"></div>
            <div class="carousel-item"></div>
            <div class="carousel-item"></div>
        </div>
    </div>
</div>

CSS CODE

         .slider {
            background-color: #ddd;
        }
        .carousel-indicators li {
            width: 14px;
            height: 14px;
            padding: 0px;
            cursor: pointer;
            background: none;
            border-radius: 50%;
            border: 2px solid #fff;
        }
        .carousel-indicators li:hover {
            background: #fff;
        }
        .slider .carousel-inner {
            display: flex;
            align-items: center;
            justify-content: left;
        }
        .carousel-inner h1 {
            z-index: 3;
            left: 4rem;
            color: #fff;
            line-height: 1.4;
            max-width: 800px;
            font-size: 4.2rem;
            position: absolute;
        }
        .carousel-inner h1 > span {
            padding: 0 1rem;
            background-color: #ed1d24;
        }
        .slider .overlay {
            top: 0;
            left: 0;
            z-index: 2;
            width: 100%;
            height: 100%;
            position: absolute;
            background-color: rgba(0, 0, 0, 0.5);
        }

        .slider .carousel-item:nth-child(1) {
            background: url(../images/slider_001.jpg) no-repeat center center;
            background-size: cover; 
        }
        .slider .carousel-item:nth-child(2) {
            background: url(../images/slider_002.jpeg) no-repeat center center;
            background-size: cover; 
        }
        .slider .carousel-item:nth-child(3) {
            background: url(../images/slider_006.jpeg) no-repeat center center;
            background-size: cover; 
        }

Answer №1

1) Avoid using div along with carousel-item until it has been properly calculated with other html elements. Instead, consider using , for instance.

2) Ensure to specify the height of carousel-item in the CSS

3) Prefer utilizing nth-of-type over nth-child

For further reference: Check out this link on CodePen

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

JavaScript is unable to execute anything that comes after the initial code, specifically document.get

<section class="blogSingle"> <div class="container"> <div class="row"> <div class="blogSingle-left col-md-8"> <div id="content3" class="blogSingleContent"></div> </div> <div class ...

"Exploring the power of Bootstrap 4 beta in combination with react-slings

I'm a beginner with webpack and react, and I'm currently working on integrating bootstrap 4-beta into react-slingshot. I'm searching for the correct method to achieve this. I have come across the bootstrap-loader, but I'm facing issues ...

Enclose every line within a span tag

I'm currently exploring ways to wrap each line of content in a span. For example, suppose I have an element structured like this: .body-copy { position: relative; width: 100%; height: auto } <div class="body-copy"> Lorem ipsum dolor s ...

When using CSS border-width:1px, I notice that the borders aren't consistently thin

I'm attempting to add thin borders to a div. My CSS code is as follows: border: solid; border-width: 1px; However, the resulting borders appear unevenly thin in my browser. The borders on the left and bottom seem thicker than those on the right and ...

Incorporate hover, onmouseover, and onmouseout features into a CSS class with proper syntax

I'm struggling with the fundamentals of syntax. I am attempting to utilize jQuery in order to target all elements within a certain CSS class, and then apply a function when the user hovers over the item. $(".item").hover(function(){$(this).fadeTo(100 ...

Tips for maintaining three image sliders in a single row in WordPress

Having three short codes displayed on my page, I am struggling to keep them on the same line. Is there a straightforward method to control the images, placing three per line? I have a CSS plugin that allows me to use DIV tags to assign a DIV for alignmen ...

Unveiling a hidden div when a JSP expression language is not empty

Is there a proper way to display a hidden div only when certain conditions are met? For example, I want to show a login error message within a div only if there is an error. <div id= "error" class="alert alert-danger" hidden="hidden" role="alert"> ...

How can I retrieve the reference number of an item by clicking a button within a list item in an unordered

Presented here is a collection of data points and a button nested within an ul <ul> <li class="mix" category-1="" data-value="600.35" style="display:block;"> <figure> <figcaption> <h3> ...

Images cannot be uploaded to the login page

Here is the code for the login.aspx page: <%@ Page Title="Log In" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="DoubleEntryForm.Account.Login" %> <asp:Content ID="HeaderContent" runat="s ...

Hovering over a div element will trigger a change in another embedded div

My HTML Code: <div id="menu"> <div class="arrows"> <div class="arrow-down"></div> </div> <div class="buttons"> <button class="home">Home</button> ...

What is causing my 100% height to be excessively large?

I'm facing an issue with my background containers, "background-overlay" and "background-gradient", as they are extending the height of the document beyond the actual content displayed. I am unsure of what could be causing this problem. It might be som ...

Text centered over an animated underline using CSS

Seeking help with my bootstrap 4 nav menu. I have implemented a CSS animation that creates an outward underline effect for the nav-link items. However, I am struggling to center the text above the line. Any suggestions on how to achieve this? I attempted ...

Responsive design not functioning properly for Bootstrap columns on website

If my display currently looks like this with three equally distanced images at the top and two images at the bottom, how can I achieve that design? I attempted using Bootstrap by setting the top 3 images as <div className="col-md-4"> and t ...

Can you create a seamless transition from a horizontal gradient to a vertical gradient in order to conceal something?

I am currently working on achieving a unique effect with three background gradients, including a horizontal mask, top border, and bottom border to seamlessly blend borders into the background: In order to achieve this effect, here is the code snippet I ha ...

Adjust the size using padding alone

My CSS specifies font size of 14px, line height of 14px, and padding of 7px on the top and bottom. The total should be 28px. When I apply these styles in a div, it results in a height of 28px. However, when applied to a ul li a element, the height becomes ...

Struggling to incorporate a radio button into my table design, despite attempting various CSS adjustments without success

After adding a radio button element to my table, I noticed it was not appearing on the page. To troubleshoot, I created a snippet with the same code and found that the radio button did show up there. Additionally, when I added a background color to see whe ...

Using Column CSS Property with Google Maps in Chrome: A Potential Bug?

I'm facing an interesting issue and I could use some help understanding or fixing it. It seems like there might be a bug or a solution to this problem. I am currently working on a layout using the CSS3 property columns. Everything looks fine in Firefo ...

Add a touch of mystery to a triangle SVG with CSS shadows

Is there a way to apply shadows to SVG images, like a triangle? I've tried using polyfill solutions but they didn't give me the desired effect. Check out this JSFiddle where I showcase what I'm trying to achieve. This is my HTML: <div c ...

Showing a cropped section of an image inside a div container

Is it possible to display a specific portion of an image within a div that is 300*300px in size while maintaining responsiveness, using only HTML and CSS? The div always occupies 33% of the page width. Here is an example of my code: HTML <div class= ...

Set the background color of a webpage depending on the data retrieved from the database when a specific radio button

I am facing a challenge with my radio buttons that are set to light up green when the page loads. However, I am working on an "order system" where I need a specific button or "locker" to appear red instead of green when the page loads. While I have succes ...