What is the best way to adjust the position of the previous and next buttons on a Bootstrap 5 carousel?

I am having trouble figuring out how to properly position the previous and next buttons in a bootstrap5 carousel. The original code I used as a template was for a carousel that displayed 4 images at once, but I changed it to display 3 images at once. I also added some space between the images.
I know that the prev/next buttons have position:absolute, so I tried changing it to position:relative and adjusting the margins, but it only made things worse.
Is there a solution to fix this issue?
The current appearance of the buttons can be seen here: buttons

<div class="container text-center my-3 mb-5 carousel2">
                    <div class="row mx-5 my-5 justify-content-between align-items-center">
                        <div id="Carousel-2" class="carousel slide" data-bs-ride="carousel">
                            <div class="carousel-inner" role="listbox">
                                <div class="carousel-item active">
                                    <div class="col-md-4">
                                        <div class="card">
                                            <div class="card-img">
                                                <img src="./images/woman1.jpg" class="img-fluid">
                                            </div>
                                            <div class="card-img-bottom"><strong>Jane Dow</strong>
                                                <p class="mt-0 me-2" style="font-size: 13px;">CEO - AXA Group</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="carousel-item">
                                    <div class="col-md-4">
                                        <div class="card">
                                            <div class="card-img">
                                                <img src="./images/man1.jpg" class="img-fluid">
                                            </div>
                                            <div class="card-img-bottom"><strong>Dave Johnson</strong>
                                                <p class="mt-0 me-2" style="font-size: 13px;">Marketing Manager - Johnson's & Co</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="carousel-item">
                                    <div class="col-md-4">
                                        <div class="card">
                                            <div class="card-img">
                                                <img src="./images/man2.jpg" class="img-fluid">
                                            </div>
                                            <div class="card-img-bottom"><strong>Roger Smith</strong>
                                                <p class="mt-0 me-2" style="font-size: 13px;">CEO - Hi-Tech Intl.</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="carousel-item">
                                    <div class="col-md-4">
                                        <div class="card">
                                            <div class="card-img">
                                                <img src="./images/woman2.jpg" class="img-fluid">
                                            </div>
                                            <div class="card-img-bottom"><strong>Diana Russel</strong>
                                                <p class="mt-0 me-2" style="font-size: 13px;">Manager - Creativity Hub</p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <a class="carousel-control-prev bg-transparent w-aut" href="#Carousel-2" role="button" data-bs-slide="prev">
                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            </a>
                            <a class="carousel-control-next bg-transparent w-aut" href="#Carousel-2" role="button" data-bs-slide="next">
                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            </a>
                        </div>
                    </div>
                </div>

Answer №1

To ensure your buttons remain stable in fixed positions, utilize the following code snippet. Assign a relative position to your carousel as the parent element for your previous and next buttons.

The combination of top and transform properties will keep your buttons centered within your container.

     .carousel {
        position: relative;
     }           
     .carousel-control-prev , .carousel-control-next {
        position: absolute;
        top: 50%;
        transform: TranslateY(-50%);
     }
     .carousel-control-prev {
        right: auto;
        left: 20px;
     }
     .carousel-control-next {
        left: auto;
        right: 20px;
     }

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

Delete any classes that start with a specific prefix

Within my code, there is a div that holds an id="a". Attached to this div are multiple classes from different groups, each with a unique prefix. I am uncertain about which specific class from the group is applied to the div in JavaScript. My goal is to r ...

HTML: Dealing with issues in resizing and resolution with floating elements on the left and right using

Encountering some issues with the HTML code below when resizing the window: 1: The right bar suddenly drops down if the width is made too small. 2: The spacing between the content and the right bar expands as the window width increases. <style ty ...

Opencart admin URL customizer (Eliminate index.php?route="")

Is there a way to conceal the index.php?route="" & user_token="" links on my Opencart admin page? I would like it to display as something like admin/dashboard instead of admin/index.php?route=common/dashboard&user_token="" ...

Discrepancy in image dimensions between Android and iOS

Currently, I am in the process of building a website and have encountered an issue with the display of images on Android and iOS phones. The image appears differently on an Android Galaxy J-5 compared to an iOS iPhone 6s screen. My goal is to make it look ...

Conceal portion in HTML until revealed

I am attempting to create 3 sections within a single HTML file using the <section id="id"> tag, and I want to be able to open each section by clicking a link in the header with <a href="#id">1</a>, and then close it when another section i ...

What is the best way to display the complete text or wrap a menu item in an Angular Material menu?

Is it possible to display the full text of a menu item instead of automatically converting it to ellipses or breaking the word? I've tried various CSS methods without success. Any suggestions? https://i.stack.imgur.com/3l7gE.png #html code <mat-m ...

There is currently no graph being shown

I've run this code but I'm not getting any output. There are no errors showing up, but I can't seem to figure out what's wrong. Can someone help me identify the issue? Thanks! <!DOCTYPE html> <html> <head> <m ...

How can I align text to the left within a dropdown menu?

I'm currently working on a simple HTML and CSS dropdown menu. Although I have managed to hide and show it, I am struggling to align the text inside the dropdown to the left. Can anyone help me figure out what I'm doing wrong? Please take a look ...

Learn how to implement a feature in your chat application that allows users to reply to specific messages, similar to Skype or WhatsApp, using

I am currently working on creating a chatbox for both mobile and desktop websites. However, I have encountered an obstacle in implementing a specific message reply feature similar to Skype and WhatsApp. In this feature, the user can click on the reply butt ...

Retrieving information from a text document by means of data-src with the assistance of jQuery

Trying to extract text from a .txt file using jQuery while utilizing Bootstrap. New to web design with some coding experience. Button in HTML: <button type="button" class="btn btn-primary-outline-btn text-btn" data-toggle="modal ...

The font displayed in Photoshop Mock Up may not be identical to the font used in HTML

(HTML Newbie) I created a design using Photoshop for my website, but the text appears differently when viewed in Firefox. I used Arial font, 18pt size, and regular weight in the mock-up, and implemented it into HTML code, yet it displays differently. Is ...

CSS/Bootstrap : troubleshooting overflow problem

Experiencing a problem with the popover control due to a display issue. The overflow property had to be set to 'visible' in order to prevent it from being hidden behind the table. overflow:visible; For a repro, please see jsfiddle: http://js ...

How can I create numerous HTML containers using Javascript?

I've been learning from this tutorial: Instead of just displaying the last database object, I want to display all of them. I have tried outputting the database contents and it's working fine. Now, I just need to adjust the HTML. I attempted to ...

The operation of 'val' is not supported by HTMLInputElement

While working with a table row, I am iterating through each cell. Inside every cell lies a text box containing some value that I need to store in an array. function dothing() { var tds = $('#'+selected+' td'); var submi ...

Keeping the header in place: fixed positioning

This particular situation is quite challenging for me. I have a webpage that requires horizontal scrolling. There is a menu at the top of the page that needs to remain centered on the page at all times. Even with the use of jQuery, I am uncertain how to ac ...

Using single quotation marks in Javascript

When the variable basis contains a single quotation mark, such as in "Father's Day", I encounter an issue where the tag is prematurely closed upon encountering the single quotation mark. 'success' : function(data) { div.innerHTML = &apo ...

In Chrome, there is a conflict between the screen width when using `position: absolute` and `position: fixed` if there is vertical

I'm in the process of developing a website with a video banner set to fixed positioning in the background, and a div that has absolute positioning covering part of the video on the bottom half. However, I've encountered an issue - when I add this ...

Add CSS styling to input text that is not empty

Is it possible to achieve this using CSS3 alone? var inputs = document.getElementsByTagName("INPUT"); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == "text") { if (inputs[i].value != "") { inputs[i].s ...

I'm having trouble getting the font to display properly on Safari (mac) similar to how it appears on

Recently, I completed a website for a client at . The owner requested the footer text to be styled similarly to the footer text on . However, upon review, it seems that the font in the lists on desiringgod appears thinner compared to the site I built. Thi ...

Effortlessly move and release Internet Explorer

Encountering drag and drop issues in Internet Explorer and Safari, while functioning correctly in Firefox 15 (untested on other versions). Dragging and dropping items between dropzones works in Safari, but sorting does not. In Internet Explorer, nothing wo ...