Troubleshoot: Issue with Active Class in Bootstrap Carousel LI Item

I modified the bootstrap 4 carousel code by splitting it into two columns. This was necessary because I wanted to move the carousel indicators outside of the carousel itself, rather than having them inside as per the default setup.

While the image-changing aspect of the carousel is functioning correctly, the issue lies with the "active" class not transitioning to any other list item.

HTML

<div class="row mx-0">
...
            </div>
        </div>
    </div>

CSS

.carousel-inner,.carousel,.carousel-item,.container#carousel-container,.fill {
    height:100%;
    min-height:700px;
    width:100%;
    background-position:center center;
    background-size:cover;
}
.slide-wrapper{display:inline;}
.slide-wrapper .container{padding:0;}

/*------------------------------ vertical bootstrap slider----------------------------*/
.carousel-inner> .carousel-item.carousel-item-next ,
...
#carousel-indicators li.active i{
    color: var(--primaryColor);
}

In order to enhance user experience on my page, I simply want to adjust the color of the active indicator dot.

Answer №1

There is a simple way to achieve this with just a little bit of CSS. The key is to have both sections ("section of indicators" and "section of images") within the carousel div (the one with the id='myCarousel'). This will give you default functionality, including the auto slide where the 'active' class is applied as well.

Below is a working snippet:

/* Make the image fully responsive */

    .carousel-inner img {
      width: 100%;
      height: 100%;
    }

    .carousel-indicators {
      display: block !important;
      height: 90% !important;
    }

    .carousel-indicators li {
      background-color: red !important;
      width: 10px !important;
      height: 10px !important;
      margin: 40% !important;
    }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

    <div class='container-fluid'>
      <h2>Demo Carousel</h2>
      <div id="demo" class="carousel slide" data-ride="carousel">
        <div class='row'>

          <div class='col-lg-1 col-md-1 col-sm-1 col-1'>
            <!-- Indicators -->
            <ul class="carousel-indicators">
              <li data-target="#demo" data-slide-to="0" class="active"></li>
              <li data-target="#demo" data-slide-to="1"></li>
              <li data-target="#demo" data-slide-to="2"></li>
              <li data-target="#demo" data-slide-to="3"></li>
            </ul>
          </div>

          <div class='col-lg-11 col-md-11 col-sm-11 col-11'>
            <!-- The slideshow -->
            <div class="carousel-inner">
              <div class="carousel-item active">
                <img src="https://www.w3schools.com/bootstrap4/la.jpg" alt="Los Angeles" width="1100" height="500">
              </div>
              <div class="carousel-item">
                <img src="https://www.w3schools.com/bootstrap4/chicago.jpg" alt="Chicago" width="1100" height="500">
              </div>
              <div class="carousel-item">
                <img src="https://www.w3schools.com/bootstrap4/ny.jpg" alt="New York" width="1100" height="500">
              </div>
              <div class="carousel-item">
                <img src="https://www.akberiqbal.com/Jumbo.jpg" alt="Akber Iqbal" width="1100" height="500">
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>

NOTE: In this stack overflow code snippet, I had to use !important for each property because it loads the custom CSS before the bootstrap.css. In your own code, place the <style>...</style> block after loading bootstrap.css, and you won't need to use !important.

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

problem with nivo slider causing content to overflow

My webpage is using nivoslider to display images. However, I am facing an issue where the images are overflowing one by one until the page fully loads. I have tried setting the overflow:hidden property in the CSS but it doesn't seem to correct the pro ...

When files are uploaded to the server, the hyperlinks fail to function properly

I am currently facing an issue with the admin side panel dropdown links on a project I am working on. The admin panel includes both regular links and dropdown elements. While the single links are functioning properly, the dropdown is not opening to displ ...

JavaScript Summation Calculation

I am currently working on calculating the sum of three scores and displaying the total as "Total:". However, I am facing an issue in dynamically updating the total whenever a score value changes. Is there a way to utilize the "onchange" event to achieve th ...

The background-size property in CSS does not seem to properly display on iPhones

Hello there! I'm facing an issue with my CSS code when it comes to displaying the image on Safari browser. It works perfectly fine on other browsers, but for some reason on Safari, the image doesn't show up correctly. I tried using a media query ...

Is there a way to implement jQuery for displaying and hiding DIVs according to checkboxes in a form submitted from a separate page?

How can I achieve the functionality of submitting a form on one page, and then dynamically showing or hiding DIVs on the next page based on the checkboxes that were selected? It's also important for the script to display custom messages depending on w ...

Seamless conversion

I have a web application created using Angular framework. Below is the code snippets for the template file and TypeScript file: HTML: <button class="btn btn-primay" (click)="changeColumnsSize()"> change column sizes</button> <div class=" ...

Out of the blue, margin-top and marin-left suddenly appeared

Within my HTML file, I have a header containing an unordered list (ul) with list items (li) and anchor (a) elements for the menu. /* ****** */ :root { --primary: #32a852; --white: #fafafa; --black: #000000; --lightgrey: #c7c7c7; - ...

Keeping the color of CSS buttons consistent can be achieved by setting specific

Here is my CSS code: .horizontalcssmenu ul{ margin: 0; padding: 0; list-style-type: none; list-style:none; } .horizontalcssmenu ul a:active{ color: #00FFFF; background: #FF0033; text-decoration: none; } /* Styles for top leve ...

How to implement pagination for JSON response data

I am currently developing an application that requires making a call to a URL in order to retrieve a JSON response. To handle the large amount of data received, I am utilizing Handlebars.js to create list items and then appending them to a unordered list ( ...

Tips for automatically floating elements to the right or left

I am currently working on a page that displays orders dynamically generated by Flask when a customer places an order. https://i.sstatic.net/W8f1s.png When clicking to expand an order, everything works smoothly if the order is on the left side. However, s ...

What is the best way to crop a background image for optimal lazy loading?

Just a quick query here - what's the best way to cut a background image for optimal lazy loading? I have an image that's 1920px wide and 5100px tall. I'm trying to figure out the best approach to cutting and loading it efficiently. Is my i ...

The sidebar is not automatically adjusting its height to match the height of the content

The initial appearance of the sidebar can be seen here: https://i.sstatic.net/epGgs.png When the content fits the original page size, everything looks fine: https://i.sstatic.net/Sfxhb.png However, once the columns are stacked on top of each other, the s ...

Seeking guidance on navigating a Bootstrap tabbed navigation menu with nested dropdowns using previous and next buttons

My template features tabbed navigation with a nested dropdown menu. The previous and next buttons are meant to provide secondary navigation through each of the tabs. The issue arises when trying to navigate through the pages in the dropdown menu using the ...

Sending a user's ID to a Bootstrap modal in Angular 4: step-by-step guide

I am currently utilizing Angular 4 for the front end and spring boot for the back end. My goal is to implement bootstrap modals to display user details when a button labeled 'user details' is clicked. This is the clients.component.html file: ...

Styling can be compromised by Angular due to selector element interference

I have a question regarding a bootstrap button group. The buttons within it are Angular components structured like this: <div class="btn-group float-right" role="group" aria-label="Basic example"> <app-action [actionType]="'inv ...

Adding Materialize CSS to an AngularJS project: A step-by-step guide

Currently, I am utilizing Yeoman to work on a brand new website using angularJS. Even after attempting bower install materialize and bower install angular-material, no changes are reflected in the design and functionality of the site. Additionally, I have ...

Exploring the integration of Javascript and PHP variables for seamless data interchange

Answering My Own Question I had a situation where I needed to use AJAX to retrieve a video from Youtube, but it required the use of a PHP file in conjunction with Javascript variables. Unfortunately, I couldn't figure out how to do it on this platfor ...

Issues with AngularJS ng-view not functioning as expected

I recently followed a tutorial on AngularJS routing and views from this guide: However, I am facing an issue where changing the view does not trigger any response. Can anyone help me figure out what I might be doing wrong? Below is the code snippet that ...

What exactly does the ::before pseudo-element accomplish?

After reviewing the documentation, I believe I have a good grasp of the purpose of ::before and ::after. It seems that they are typically used in conjunction with other elements. However, the webpage I am examining contains the following code: <body> ...

Receive a pair of distinct arrays through a text field submission

I have a form on my website with a single textarea input. Visitors can enter text in the textarea in the following format: 5x Blue Flower 2 Red Flower 3* Yellow Flower Purple Flower I need to extract two arrays from this input - one for the quantity an ...