The ongoing battle between Carousel full page image slider and multi div slider in Bootstrap 4

I need a full-page carousel image slider in one div container and a multi-div slider in another div container on my homepage. Unfortunately, due to some conflicting class names (such as carousel slide, carousel-inner, etc.), they are interfering with each other and causing the multi-div slider to malfunction.

HTML for Full Page Image Slider

<div id="demo" class="carousel slide" data-ride="carousel">

          <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>
          </ul>

          <div class="carousel-inner">
            <div class="carousel-item active">
              <img src="{{ url('images/img1.jpg') }}" alt="Los Angeles">
            </div>
            <div class="carousel-item">
              <img src="{{ url('images/img3.jpg') }}" alt="New York">
            </div>
            <div class="carousel-item">
              <img src="{{ url('images/img5.jpg') }}" alt="New York">
            </div>
          </div>

          <a class="carousel-control-prev" href="#demo" data-slide="prev">
            <span class="carousel-control-prev-icon"></span>
          </a>
          <a class="carousel-control-next" href="#demo" data-slide="next">
            <span class="carousel-control-next-icon"></span>
          </a>
        </div>
  

HTML for Multiple Div Slider

<div class="carousel slide" id="myCarousel">
      <div class="carousel-inner">
        <div class="item active">
          <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/e499e4/fff&amp;text=1" class="img-responsive"></a></div>
        </div>
        ...
      </div>
      <a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
      <a class="right carousel-control" href="#myCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
    </div>
  

Check out the issue on the homepage's images here

If you have any suggestions on how to resolve this conflict, please feel free to share!

Answer №1

From my understanding of your requirements, I am making the following assumptions:

  1. You require a full-screen Carousel at the top of the page with rotating images.
  2. You also need a second carousel immediately below the first one with rotating images as well.
  3. You are utilizing Bootstrap through CDN links and have not precompiled it yourself.

When using Bootstrap via CDN, it follows a 12-column layout structure. In your second carousel, you have included 9 columns which exceed the limit causing rendering issues.

To ensure that the top carousel is displayed in full screen, you will need to apply some CSS rules to make sure it adjusts to the screen's dimensions.

I came across an example of a full-screen carousel (credits to the developer) - Full Screen Carousel Example

By targeting the top carousel with specific CSS and placing a separate div container for the second carousel, you can have more control over their appearance.

The images in your first carousel serve as backgrounds to the containers, allowing them to render properly when the height and width are defined using CSS.

CODE

$('#carouselExampleIndicators').carousel({
  interval: 400,
  keyboard: false,
  pause: "hover",
  ride: true,
  wrap: true
});

$('#carousel2').carousel({
  interval: 4000,
  keyboard: false,
  pause: "hover",
  ride: false,
  wrap: true
});
header .carousel-item {
    height: 100vh;
    min-height: 350px;
    background: no-repeat center center scroll;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<header>
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
      <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
      <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner" role="listbox">
      <!-- Slide One - Set the background image for this slide in the line below -->
      <div class="carousel-item active" style="background-image: url('https://source.unsplash.com/LAaSoL0LrYs/1920x1080')">
        <div class="carousel-caption d-none d-md-block">
          <h2 class="display-4">First Slide</h2>
          <p class="lead">This is a description for the first slide.</p>
        </div>
      </div>
      <!-- Slide Two - Set the background image for this slide in the line below -->
      <div class="carousel-item" style="background-image: url('https://source.unsplash.com/bF2vsubyHcQ/1920x1080')">
        <div class="carousel-caption d-none d-md-block">
          <h2 class="display-4">Second Slide</h2>
          <p class="lead">This is a description for the second slide.</p>
        </div>
      </div>
      <!-- Slide Three - Set the background image for this slide in the line below -->
      <div class="carousel-item" style="background-image: url('https://source.unsplash.com/szFUQoyvrxM/1920x1080')">
        <div class="carousel-caption d-none d-md-block">
          <h2 class="display-4">Third Slide</h2>
          <p class="lead">This is a description for the third slide.</p>
        </div>
      </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
    <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
  </div>
</header>

<div id="carousel2" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <a href="#">  
          <img class="d-block w-100" src="https://place-hold.it/500x300?text=Slide%201&fontsize=30" alt="First slide">
          </a>
    </div>
    <div class="carousel-item">
      <a href="#">  
          <img class="d-block w-100" src="https://place-hold.it/500x300?text=Slide%202&fontsize=30" alt="Second slide">
          </a>
    </div>
    <!-- Add more carousel items as needed -->
  </div>
  <a class="carousel-control-prev" href="#carousel2" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carousel2" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

<!-- Include JS scripts -->

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

What is the process of retrieving user input from an HTML form and locating specific data within it?

Here is the structure of my form: <div id="employeeinfo" style="padding:40px" class="employee-body"> <form id="employeeform" title="" method="post"> <label class="title">First Name</label> < ...

The simple method for incorporating line feed in <s:textarea>

Hey there, I'm currently utilizing struts 2 UI and I seek a means to restrict the number of characters in each row to only 16. Additionally, I want to impose a maximum length limit of 32 characters. Despite my attempts using the 'row' and &a ...

Is it possible to apply styles to javascript elements without relying on img class? Additionally, how can I incorporate an onclick button while maintaining a fully functional navigation bar?

My current project involves creating an interactive collage where users can click around and have pictures pop up at the clicked location. The functionality works as intended, but now I'm facing issues with the navigation bar not being clickable. Addi ...

What is the best way to remove the left margin from a MuiTreeItem-group?

I'm working with the MUI tree component and I want to remove the left margin of the second layer of MuiTreeItem-group I attempted to use makeStyles to address this issue, but it didn't have the desired effect const useStyles = makeStyles(() => ...

Using Jquery to Deactivate Field upon Meeting Conditions

In my form, there are 15 rows with unique IDs ranging from 1 to 15 (row_id). Each row consists of a select field and multiple text fields. My goal is to disable row_id 5 if the select option in rows 6 or higher is anything other than 0, and to disable row ...

Select a division and retrieve the identification of a different division

I am looking to trigger an event by clicking on one element and extracting the ID from a separate, unrelated div. Here is my attempt: $(".map_flag").on("click",function(){ var selectedID = ($(this).attr("data_modal")); $("#" + selectedID).fade ...

Is it feasible to verify for vacant dates with a single click?

Is there a way to determine if a date value is empty, and if it is, display a popup indicating so? After some research, I stumbled upon a similar issue where the date value was always filled with a default "mm/dd/yyyy" value. The solution provided involv ...

AngularJs - Customizable dynamic tabs that automatically adapt

Below is the HTML code snippet: <div> <ul data-ng-repeat ="tab in tabs"> <li data-ng-class="{active: tab.selected == 'true'}" message-key="Tab"> </li> </ul> </div> As shown ...

Require assistance in transitioning the ajax and php code for use within Wordpress

After following various guides, I have managed to reach this point: add_action('wp_enqueue_scripts', 'do_enqueue_scripts'); function do_enqueue_scripts() { wp_enqueue_script('Java', plugins_url( '/js/form.js', ...

How can I retrieve the value from one of these buttons and dynamically set the class to "active" for the button that was clicked by utilizing jQuery?

<div class="hide-below-1200 btn-group" style="padding: 5px 0 5px 0;" data-toggle="buttons" role="group"> <button class="btn btn-default btn-sm active year-btn">All</button> <button class="btn btn-default btn-sm year-btn">201 ...

php executing javascript - error

I have a question regarding my PHP file code: echo '<script type="text/javascript">'; echo '<audio id="player" src="../cdh/ba1.mp3"></audio>'; echo '<a onclick="document.getElementById( ...

"Techniques for dynamically transferring data from a PHP array to a JavaScript variable during runtime

I have developed a website and mobile app using PhoneGap Build. In the site, I am loading arrays with PHP into JavaScript to display ads. The ads show up properly on the website but not on the iOS and Android apps where there is just an empty space. Intere ...

Aligning table data elements within a division

Currently working on revamping a tech night website for my school. I made some changes to the navbar, switching it from the side to the top. However, I'm struggling to get the table data and menu to center properly within the div. If you'd like ...

Can jQuery script be used within a WordPress page for inline execution?

Can jQuery be executed in the middle of a page (inline)? I attempted to run the following code within a custom WordPress template.... <script type="text/javascript"> jQuery(document).ready( function() { jQuery(".upb_row_bg").css("filter","blur(30 ...

Ensuring scope safety in jQuery AJAX requests

My intuition suggests that if I am on a laggy server and the user triggers two events quickly enough, the value of c in the success function will be based on the most recent event, potentially causing func1 to use the incorrect value. This is merely a hypo ...

The functionality of the Bootstrap4 accordion is not functioning according to my expectations

My goal is to create a unique e-commerce checkout page design. Each panel would be opened sequentially, with the next panel unfreezing when the action button of the current panel is clicked. However, I seem to be making a mistake as it is not working as in ...

Step-by-step guide on bypassing Content Security Policy with JavaScript

I have Content Security Policy enabled for security purposes in my current project, but I need to disable it for certain JavaScript files. Can this be done? I am trying to make API calls from my JavaScript files in order to retrieve results. ...

What is the best way to position a button directly to the right of a text box with no space in

Is there a way to perfectly align a submit button to the right of a text or search box, matching the height of the search box, and eliminating any unwanted white space between them? This is my current setup: <input type="text" value="" placehold ...

Is there a way to stop Bootstrap from automatically bolding the font?

When testing this simple example without the bootstrap link, everything seems to be working correctly: Hovering over any word changes its color to red, and when hovering away it returns to black. But as soon as the bootstrap link is included, the text bec ...

Having issues with the onchange attribute in the rails text_field_tag not functioning as

Hey there! I am working on an ajax submitted form that includes only a text_field_tag. My goal is to have the form submit as soon as the user begins typing their search string. Thankfully, bandwidth and lag are not concerns since the application will be ho ...