Arrange the next and previous buttons on the top right corner of the Bootstrap Carousel, ensuring they are situated closely together

I am currently utilizing the Bootstrap 4 carousel. My goal is to adjust the position of the next and previous buttons to be in the top right corner, close to each other. I have been able to achieve this, but I suspect that there may be an error in my CSS code because when I resize the screen, the buttons disappear.

Here is the HTML code:

<div id="featured" class="carousel slide" data-ride="carousel">
  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="one.jpg">
    </div>
    <div class="carousel-item">
      <img src="two.jpg" >
    </div>
    <div class="carousel-item">
      <img src="three.jpg" >
    </div>
  </div>
  <!-- Left and right controls -->
 <a class="carousel-control-prev" href="#featured" data-slide="prev">
   <span class="fa fa-arrow-circle-left fa-2x" style="color:green"></span>
  </a>
  <a class="carousel-control-next" href="#featured" data-slide="next">
   <span class="fa fa-arrow-circle-right fa-2x" style="color:green"></span>
  </a>
</div>

Below is my CSS code:

.carousel-control-prev,
.carousel-control-next{
  width:20px;
  height: 20px;
  background-color: none;
  top:calc(-20% -25%);
  opacity:.8;
}
.carousel-control-prev{
 left:1090px !important;
}

Answer №1

When the user's viewport reaches or goes below <code>1090px
, using left:1090px !important will create problems. This is because it is pushing the element 1090px from the left side.

Instead, consider something like

.carousel-control-prev{
  left: unset;
  right: 30px;
}

By implementing this, you will have control over the element from the right side as it is being positioned at the upper-right corner.

$('.carousel').carousel()
.carousel {
  background: black;
}

.carousel .carousel-control-prev,
.carousel .carousel-control-next {
  width: 20px;
  height: 20px;
  background-color: none;
  top: calc(-20% -25%);
  opacity: .8;
}

.carousel .carousel-control-prev {
  left: unset;
  right: 30px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

<div id="featured" class="carousel slide" data-ride="carousel">
  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="https://via.placeholder.com/650x200">
    </div>
    <div class="carousel-item">
      <img src="https://via.placeholder.com/651x200">
    </div>
    <div class="carousel-item">
      <img src="https://via.placeholder.com/652x200">
    </div>
  </div>
  <!-- Left and right controls -->
  <a class="carousel-control-prev" href="#featured" 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="#featured" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

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

PHP contact form not properly sending complete submission data

I'm facing an issue with my HTML contact form that utilizes JavaScript for a change function. Essentially, I have a dropdown menu for different subjects, and based on the selected option, specific fields should appear. However, when a user fills out t ...

Determining the cursor's location within a textarea element

I am currently working on a React Project and I have a specific functionality in mind. I want to create a feature where as a user types into a Textarea, suggestions will appear in the form of a popover list right next to the cursor position. To implement ...

Is there a way to adjust the scrolling speed of a background image to be slower than the rest of

I'm searching for an example similar to this: Are there any efficient javascript solutions available? I've had difficulty implementing the code I've come across so far. ...

A helpful tip for dynamically adjusting the canvas size is to utilize its height and width attributes to resize it whenever it undergoes a change

I am encountering an issue with the canvas element in my code. The canvas is supposed to update whenever its containing div is resized. window.addEventListener('resize',function() { let mapwidth = $('.canvas').attr("width") l ...

How can I use PHP to update and select on the same page simultaneously?

Having always been able to do something similar in other languages, I'm facing a few difficulties with PHP. My goal is to load a page that displays all the values from a form (created with a SELECT) and then update them all when clicking a "CHANGE" bu ...

Tips for addressing the issue of button flickering due to CSS transitions

Is there a solution to prevent flickering without compromising the intended design? The issue arises when hovering over a moving or animated element and accidentally un-hovering because it moves beneath the cursor. <!DOCTYPE html> <html> &l ...

Arrange the "See More" button in the Mat Card to overlap the card underneath

I'm currently working on a project that involves displaying cards in the following layout: https://i.stack.imgur.com/VGbNr.png My goal is to have the ability to click 'See More' and display the cards like this: https://i.stack.imgur.com/j8b ...

Avoid jQuery ContextMenu Submenu Items from Expanding in Size on Mobile Devices

Recently, I started using the jQuery contextMenu which can be found at . The issue I encountered involves a menu with a submenu. Whenever I try to access the submenu items on mobile Safari or Chrome, the size of the menu items suddenly doubles and gets cu ...

Clicking a button in jQuery will automatically scroll to the far left

I am facing a challenge with my webpage where inline block divs are being appended each time a link is clicked, causing the total width to eventually go off the page (which is intentional). I would like to implement an animated scroll feature that automati ...

Off-center rotation of an element - seeking solution [closed

This question has been closed. It requires additional details for debugging. Answer submissions are currently not accepted. ...

Eliminate any undefined data in the popup map of Javascript

I am working with JSON data that is being displayed in a pop-up on a map. In cases where there is missing data (Visibility), the word undefined appears in the pop-up. Is there a way to remove the undefined text so that it does not show up in the pop-up? ...

Applying CSS to inherit styles

I have a group of divs with a similar style, but each one has different padding and margin settings. Here is an example: <div class="mainStyle" id="cc">CC</div> <div class="mainStyle" id="bb">BB</div> <div class="mainStyle" id=" ...

"Integrating FullCalendar with Cloud Firestore for seamless data management

Is It Possible to Integrate Observable with FullCalendar? I have a collection in Cloud Firestore and I want to display the data from this collection in real-time on FullCalendar. Although I know that using an Observable is necessary for this task, it see ...

Always keep your phone in landscape orientation for optimal website viewing

Currently, I am facing an issue with my website where it functions perfectly on mobile devices in landscape orientation but elements get distorted when viewed in portrait mode. Is there a method to ensure that the website is always displayed in landscape ...

What is the best method for populating a text area in Pharo with HTML content?

When logging in through Pharo using an HTML form, you can utilize the method of Znclient called formAt:add: followed by a post. I'm interested to know how I can fill a textArea in an HTML form and then make a post request. Is there a specific method f ...

Modifying color scheme in ASP.NET web application's table

Although I'm not very familiar with this, I'll try to help out. I have an ASP.Net MVC web app in Visual Studio where one of my views, called View Details, contains a table that displays colors based on a specific scale. This scale consists of onl ...

Slick slider issue: Unexpected TypeError - the slick method is undefined for o[i]

I'm facing an issue where, upon clicking the search button, I want the previous search results to clear and new ones to be displayed. However, this action triggers a slick slider error, causing all items to align vertically instead of in the intended ...

Resetting the value of a radio button input option to null using Angular2 ngModel

In my Angular2 application, I am attempting to implement radio button inputs using ngModel and value. The goal is to have three options: true, false, and null. However, I am struggling to assign a value of null to one of the inputs. Ideally, when nothing ...

Invisibility Problem

As a newcomer to web design, this is only the second website I have ever created. However, I am facing an issue with my Nav bar that I cannot seem to resolve. I want my "Other Pages" section to be visible when the screen size is below 600px and hidden when ...

Limiting the click event to the parent div only

I've encountered a problem with my overlay setup. I have an overlay with a child div inside, and I want the overlay to close only when the user clicks on the overlay itself, not the child div. Even though I've implemented the closing function, it ...