Left-aligned Bootstrap carousel design

Recently, I've been working on tweaking this code to make it Bootstrap 4 compatible and left aligned. However, I'm encountering two persistent issues that I can't seem to resolve:

  1. The right side keeps getting cut off even though I intended for it to display at 100%
  2. When you click on the arrow (carousel-control-prev), there's an annoying white space that appears before the other carousel items slide in

If anyone has any insights or suggestions on what might be going wrong with my code, please let me know. Here's the snippet I'm currently working with:

$(document).ready(function() {
  $('#carouselExampleControls').carousel({
    interval: 0
  })
  $('.carousel .carousel-item').each(function() {
    var next = $(this).next();
    if (!next.length) {
      next = $(this).siblings(':first');
    }
    next.children(':first-child').clone().appendTo($(this));
    if (next.next().length > 0) {
      next.next().children(':first-child').clone().appendTo($(this));
    } else {
      $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
    }
  });
});
.carousel,
.carousel-inner,
.carousel-inner>.carousel-item {
  overflow: hidden;
}

.carousel-inner>.carousel-item.active,
.carousel-inner>.carousel-item-next {
  display: flex;
  flex-wrap: nowrap;
  width: auto;
}

.carousel-inner:before {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 94%;
  left: 0;
  content: "";
  display: block;
  background-color: #fff;
  z-index: 2;
}

.carousel-inner:after {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: 100%;
  content: "";
  display: block;
  background-color: #fff;
  z-index: 2;
}

.carousel-control-prev {
  opacity: 1;
  background: black;
  height: 70px;
  width: 70px;
  top: 50%;
  left: 100px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta.2/css/bootstrap.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

<div class="coontainer-fluid">
  <div class="col-md-7 text-center">
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel" data-interval="false">
      <div class="carousel-inner">
        <div class="row carousel-item active">
          <div class="col-5">
            <div class="card">
              <div class="card-body text-left d-flex flex-column justify-content-end px-4 py-5">
                <div class="d-inline">
                  <a href="#" class="card-link">Link</a>
                </div>
                <h5 class="card-title">Title</h5>
                <p class="card-text">Text goes here</p>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
              </div>
            </div>
          </div>
        </div>
        <div class="row carousel-item">
          <div class="col-5">
            <div class="card">
              <div class="card-body text-left d-flex flex-column justify-content-end px-4 py-5">
                <div class="d-inline">
                  <a href="#" class="card-link">Link</a>
                </div>
                <h5 class="card-title">Title</h5>
                <p class="card-text">Text goes here</p>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
              </div>
            </div>
          </div>
        </div>
        <div class="row carousel-item">
          <div class="col-5">
            <div class="card">
              <div class="card-body text-left d-flex flex-column justify-content-end px-4 py-5">
                <div class="d-inline">
                  <a href="#" class="card-link">Link</a>
                </div>
                <h5 class="card-title">Title</h5>
                <p class="card-text">Text goes here</p>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
              </div>
            </div>
          </div>
        </div>
        <div class="row carousel-item">
          <div class="col-5">
            <div class="card">
              <div class="card-body text-left d-flex flex-column justify-content-end px-4 py-5">
                <div class="d-inline">
                  <a href="#" class="card-link">Link</a>
                </div>
                <h5 class="card-title">Title</h5>
                <p class="card-text">Text goes here</p>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
                <a href="#" class="btn btn-block text-left pl-0">Button</a>
              </div>
            </div>
          </div>
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      </a>
    </div>
  </div>
</div>

Answer №1

Bootstrap utilizes a 12-column grid system. To address the issue of grouping three slides into one row, assign each slide a class of col-4. Furthermore, I made adjustments in the classes

.carousel-inner > .carousel-item.active
and
.carousel-inner > .carousel-item-next
, changing width:auto; to width: 100%;.

<div class="container-fluid">
    <div class="row">
        <div class="col-12 text-center">
            <h3>Bootstap 4 Carousel</h3>
            <h6>Customized to advance a single slide, and reveal part of adjacent slides</h6>
            <div class="carousel slide" id="myCarousel">
                <div class="carousel-inner">
                    <div class="row no-gutters carousel-item active">
                        <div class="col-4">
                            <div class="d-inline">
                              <a href="#" class="card-link">Link</a>
                            </div>
                            <h5 class="card-title">Title</h5>
                            <p class="card-text">Text goes here</p>
                            <a href="#" class="btn btn-block text-center pl-0">Button</a>
                            <a href="#" class="btn btn-block text-center pl-0">Button</a>
                        </div>
						... (continued with remaining slides)
                    </div>
                    <div class="row no-gutters carousel-item">
                        ... (content for second set of slides)
                    </div>
                    <div class="row no-gutters carousel-item">
                        ... (content for third set of slides)
					</div>
                     <div class="row no-gutters carousel-item">
                        ... (content for fourth set of slides)
                    </div>
                </div>
            </div>
        </div>
        <div class="col-12 text-center py-3">
            <a class="left carousel-control mx-4 text-dark" href="#myCarousel" data-slide="prev"><i class="fa fa-chevron-left"></i></a>
            <a class="right carousel-control mx-4 text-dark" href="#myCarousel" data-slide="next"><i class="fa fa-chevron-right"></i></a>
        </div>
    </div>
</div>

Check out the demo here.

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

Calculating the size of grid thumbnails or items using the calc() function

I am currently working on building a responsive portfolio grid that spans the full width of the screen. To achieve this, I have set the width of the items using calc() and ensured that the thumbnail image fills the entire div by applying the following CSS: ...

Expanding using CSS3 to ensure it doesn't take up previous space

Currently, I am working on an animation for my web application. More specifically, I am looking to scale certain elements using CSS3 with the scaleY(0.5) property. These elements are arranged in a vertical list, and I want to ensure that they do not take u ...

Ensure the accordion design is adaptable to various screen sizes and orientations, as it is currently only allowing

I'm struggling to achieve responsiveness with the FAQ Accordion on my website. When it initially loads collapsed, the space where it should expand appears blank. I need it to dynamically adjust and create more room when opened up. Additionally, when a ...

The video is not extending to the full width of the container

Looking at the image I've attached, it's clear that the video is not covering the full width as desired. Can someone pinpoint where I'm making a mistake? Here is the image for reference: Image of the div and video Here's the snippet of ...

Faulty toggle functionality within a JavaScript-created accordion panel

HTML I'm looking to add a FAQ question within the div with the class "section-center" <body> <section class="questions"> <div class="title"> <h2>FAQ SECTION</h2> < ...

What is the best way to position images and URLs in div elements using CSS?

Currently, I am on a journey to become a Front End Developer through Udacity. As part of my learning process, I have a project that needs to be submitted. Unfortunately, I encountered some issues that I couldn't resolve on my own. Specifically, I&apos ...

Troubles with CSS in Wordpress

Hey there! I'm currently working on some wordpress tasks and running into an issue with the code. Everything looks good in the first two sections, but the third section is displaying at the top. Please refer to the attached image for a visual of the p ...

How can custom CSS and JS be loaded in Sencha Touch based on the user's device - PC, tablet, or smartphone?

Is there a way to configure a webpage so that when the user is accessing it from a PC (using Safari/Chrome/Firefox), they see the "normal" version of the page, but if they are using an iPad to view the same URL, they get Sencha Touch (css, js) files in t ...

Issue with the positioning of bootstrap popover after content is added

Having trouble writing a function that adds a textarea to the bottom of a popover content when clicking on a button. The issue is that once the textarea is displayed, the popover extends downward and obscures the text. I'm looking for a solution where ...

How can I integrate a timer into an Angular carousel feature?

I have put together a carousel based on a tutorial I found on a website. Check out the HTML code for my carousel below: <div class="row carousel" (mouseover)="mouseCheck()"> <!-- For the prev control button ...

Ways to adjust the font size in the title using HTML

Looking to adjust the text size within an h4 title. Hoping to make some letters smaller than others while keeping all in capital form. Any assistance is greatly appreciated. Thank you! ...

Conceal the div once it reaches the top of the webpage

Is there a way to hide an "h1" element when its parent div reaches the top of the page and then show it again when it moves down using both JQuery and CSS? I attempted to utilize a scroll listener in JQuery to toggle a class, but this resulted in the "h1" ...

Stop the Bootstrap navbar from breaking into separate lines when resizing the screen by ensuring it collapses into an icon

I have a straightforward Bootstrap Navbar that contains just a few items. When the width is less than 768, it displays in two rows. How can I make both items display in a single row at all widths without using the collapse feature? <nav class="na ...

Updating the color scheme of the selected nav-item and showcasing the corresponding page in relation to the navbar selection

I have been trying various methods, but I am unable to change the background color of an active navigation item and also display the corresponding page. Important: The jQuery code below successfully changes the background color of the navbar list item. Ho ...

Image background is not showing up in the input field

It seems like I've hit a roadblock with this issue. Despite my best efforts, I can't seem to find a solution. You can view the problem LIVE HERE. The banner's two input boxes should have background images displayed, but they are not showin ...

Utilizing JavaScript Function within a Modal Overlay

Displayed on the page is a table with various records fetched from a database. Each record has a button that, when clicked, opens up a corresponding record in a modal popup. This popup also allows for updating the record. While the popup is opening correct ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...

IE11 Experiencing Overflow Issue with List Item Pseudo Element Numbers

Having a simple unordered list of links and using pseudo elements to generate numbers for the list, I encountered an issue with centering the number vertically within its circle background in Internet Explorer 11. Here is the HTML code: <ul> < ...

Position the text alongside the Facebook emblem

I am having trouble getting the text Follow Us to align on the far right next to the Facebook Icon. I added the float:right property, but it is not working as expected. Here is the code snippet: <a href="#" target="_blank" style="font-family: Arial, ...

Having trouble getting CSS headers to work smoothly with iPhone?

After creating a web application with CSS, the initial GUI was exactly how I wanted it to be. However, within 3 seconds of loading the page, the GUI would change. The HTML code for my header is as follows: <div id="Slideshow"> <img src="image/s1 ...