Ways to create space between the columns in a bootstrap carousel with multiple items and the previous and next buttons

I'm currently utilizing Bootstrap 4 and have created a multiple item carousel as shown in the image below: https://i.sstatic.net/NbO7u.png

While the carousel is functioning properly, I'm facing the issue of not being able to add spacing between each column or item. Additionally, I do not want half of the fifth column to be visible. I've tried applying padding classes to the columns and carousel items, but it hasn't resolved my problem. Also, when I add padding to the carousel, there is no padding added from the left side.

Below is the code I'm using:

HTML:

<div class="col-12">
<div id="populars" class="carousel slide w-100" data-ride="carousel">
<div class="carousel-inner w-100 p-5" role="listbox">
<div class="carousel-item active bg-danger mx-2">
<div class="col-lg-3 col-md-6 card p-1 " style="line-height:1.2;">
<img class="img-fluid card-img-top" src="a.jpg">
</div>
</div>
<div class="carousel-item">
<div class="col-lg-3 col-md-6 card p-1 " style="line-height:1.2;">
<img class="img-fluid card-img-top" src="a.jpg">
</div>
</div>
<div class="carousel-item">
<div class="col-lg-3 col-md-6 card p-1 " style="line-height:1.2;">
<img class="img-fluid card-img-top" src="a.jpg">
</div>
</div>
<div class="carousel-item">
<div class="col-lg-3 col-md-6 card p-1" style="line-height:1.2;">
<img class="img-fluid card-img-top" src="a.jpg">
</div>
</div>

</div>
<a class="carousel-control-prev w-auto" href="#populars" role="button" 
data-slide="prev">
<span class="carousel-control-prev-icon bg-dark" aria-hidden="true"> 
</span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next w-auto" href="#populars" role="button" 
data-slide="next">
<span class="carousel-control-next-icon bg-dark" aria-hidden="true"> 
</span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div class="btn btn-danger p-3 p-md-4 mx-auto mt-5 rounded-0">
show menu
</div>
</div>
</div>

CSS:

@media (min-width: 320px) {
#populars .carousel-inner .carousel-item-right.active,
#populars .carousel-inner .carousel-item-next {
transform: translateX(100%);
}
#populars .carousel-inner .carousel-item-left.active,
#populars .carousel-inner .carousel-item-prev {*
transform: translateX(-100%);
}
}
/* medium - display 2  */
@media (min-width: 768px) {
#populars .carousel-inner .carousel-item-right.active,
#populars .carousel-inner .carousel-item-next {
transform: translateX(50%);
}

#populars .carousel-inner .carousel-item-left.active,
#populars .carousel-inner .carousel-item-prev {
transform: translateX(-50%);
}
}

/* large - display 3 */
@media (min-width: 992px) {
#populars .carousel-inner .carousel-item-next {
transform: translateX(25%);
}
#populars .carousel-inner .carousel-item-left.active,
#populars .carousel-inner .carousel-item-prev {
transform: translateX(-25%);
}
}
@media (max-width: 768px) {
#populars .carousel-inner .carousel-item>div {
display: none;
}
#populars .carousel-inner .carousel-item>div:first-child {
display: block;
}
}
#populars .carousel-inner .carousel-item.active,
#populars .carousel-inner .carousel-item-next,
#populars .carousel-inner .carousel-item-prev {
display: flex;
}
#populars .carousel-inner .carousel-item-right,
#populars .carousel-inner .carousel-item-left {
transform: translateX(0);
}

Thank you in advance for any assistance you can provide.

Answer №1

To create some space between your elements, you can utilize the gap property. I recently worked on a project where I implemented BS4 Carousel and used the gap property to separate my cards.

Here is an example:

HTML

  <div class="carousel-inner">
                    <div class="carousel-item">
                        <div class="slide-box">
                        ....your content here....

CSS:

.slide-box {
display: flex;
gap: 2rem;
}

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 best way to position these two images side by side in a row?

Is there a way to place both images in the same row while also adding subtitles to each? I've tried different approaches, but I can't seem to align them properly with the subtitles included. <div class="container row-info"> <div cla ...

Enhancing HTML "range" element with mouse scroll functionality for incrementing values in step increments

I'm working on developing a scroll feature that operates independently from the main window's scrolling function. I aim to trigger specific events in the primary window based on interactions with this separate scrollbar. The only solution I coul ...

As the screen size shrinks, two components merge together

One issue I'm facing with my site is the component called NavPanel. This consists of two components - a back button (BackToButton) and a search field (SearchTextField). Everything looks fine on a standard screen size, but when the screen size decrease ...

Having difficulty getting the HTML table formatting and colors to display properly

Explore the custom netting options for baseball and softball batting cages here. It seems like there might be an issue with displaying tables and background colors in the description field. We'll look into it! ...

Is anyone else experiencing issues with loading a font from a CDN? It works perfectly fine on Chrome Browser and Safari for iOS Simulator, but for some reason, it's not loading

It's driving me a bit crazy as I'm not sure where I've gone wrong. I'm currently working with NextJS and have loaded this font into my <Link />. While it displays perfectly on Chrome and Safari in the iOS simulator, it fails to l ...

Using the <li> element as the primary container for a series of <li>'s within a <ul> is

For my form requirement, I am utilizing Jotforms. After downloading the code, I am currently in the process of customizing the CSS and HTML to fulfill my design needs. Jotforms uses a set of ul , li for managing its HTML structure. However, I encountered ...

What is the best way to combine a navbar with a video background?

Recently, I delved into Bootstrap and attempted to execute a code for a navbar with a video background. This is what my attempt looked like: HTML Code: <html> <head> <title>Medical</title> <meta charset="UTF-8&qu ...

Is there a way for me to design a button that includes an image?

I'm looking to create a button on my webpage using an image that will link to other pages. I want the flexibility to use both small and large text on this button. The specific image I want to use is: So far, I've attempted some coding but haven ...

Can you provide instructions on creating a small border at the center of an h1 heading?

What is the best way to create a small border in the center of an h1 text element? ...

Creating a progress bar with blank spaces using HTML, CSS, and JavaScript

Upon running the code below, we encounter an issue when the animation starts. The desired effect is to color the first ten percent of the element, then continue coloring incrementally until reaching 80%. However, as it stands now, the animation appears mes ...

Why are my video files exhibiting inconsistent behavior?

I've encountered an issue with the code on my website where I'm trying to display a 40-second video. The video converter I used seems to have added extra video types, which may be causing the problem. Here's what the HTML code looks like: ...

Trick to keep horizontal element alignment intact when scroll bar appears

Currently, all my pages are designed with the standard fixed-width-margin-left-right-auto layout. .container{ width:900px; margin:0 auto; } An issue arises when some of these pages exceed the height of the window, requiring a vertical scroll ba ...

Turn off smooth scrolling in Bootstrap 5 using HTML and CSS techniques

On my website, I have implemented anchor links that activate smooth scrolling when clicked, thanks to the Bootstrap feature. However, the unique layout of my website requires me to turn off smooth scrolling in either the HTML or CSS code. I appreciate an ...

How to implement scrollspy in Bootstrap 4 without relying on nav or list-group components?

Is it possible to implement scrollspy functionality without utilizing the nav or list-group elements? According to Bootstrap's documentation on scrollspy, it is typically restricted to use within nav or list group components. DOCUMENTATION How Scroll ...

Attempting to conditionally apply CSS to a component based on a prop, but unfortunately it is not functioning as expected

.storyMobile{ color:green; } .storyWeb{ color:red; } <div class="storyMobile"> hii </div> <div class="storyWeb"> hii </div> //main view <div> <story :story="stories[0]"/> </div> //here it prints ...

Table that can be scrolled through

Back in 2005, Stu Nichols shared a technique for creating a fixed header with scrolling rows in a table on this site. I'm curious if there are any newer methods or improvements to achieve the same effect, or is Stu's approach from 2005 still con ...

How can I stack images on top of each other using Div, CSS, and ZIndex?

Currently, I am facing a challenge with overlapping 5 pictures. Despite reading numerous tutorials on CSS and div overlapping techniques, I still don't quite understand how to achieve it. The container where I want these images to overlap has a widt ...

The :empty selector is failing to function properly in @media print queries

Currently, I am working in Twig on Symphony and have encountered an issue with an empty div that needs to be hidden in print mode. <div class="form-fields__list"> </div> Surprisingly, the :empty selector works perfectly fine on the screen, bu ...

Upon clicking the checkbox, only the ul tag will be displayed on the screen

It's puzzling to me that when I click on the checkbox, only the ul tag with id=menu is visible on the screen, not id=social. I need to ensure display:block is set for every ul tag. .show-menu { display:block; } #menu{ float:left; } #social{ ...

Trouble with ASP.NET Master Page CSS Rendering Incorrectly

My CSS seems to be causing some trouble as the DIVs are not aligning as they should. Instead, they are just wrapping around the text and not adjusting the page layout properly. Here is an example of my CSS: body { height: 95%; width: 100%; ma ...