Vertical alignment of captions in Bootstrap 4 carousels

I need help centering the caption on my bootstrap 4 carousel. I've tried various methods like adding align-items-center, justify-content-center, and text-center to both carousel-item and carousel-caption, but nothing seems to work.

body {
  overflow-x: hidden;
  height: 100%
}

.carousel-item:after {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
}

.carousel-item {
  height: 100vh;
}

.carousel-image-1 {
  background: url('../images/miami1.jpeg');
  background-size: cover;
}

.carousel-image-2 {
  background: url('../images/miami2.jpeg');
  background-size: cover;
}

.carousel-image-3 {
  background: url('../images/miami3.jpeg');
  background-size: cover;
}
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
            <li data-target="#myCarousel" data-slide-to="0"></li>
            <li data-target="#myCarousel" data-slide-to="1" class="active"></li>
            <li data-target="#myCarousel" data-slide-to="2"></li>
        </ol>
        <div class="carousel-inner">
            <div class="carousel-item carousel-image-1">
                <div class="container">
                    <div class="carousel-caption text-right mb-5">
                        <h1 class="display-3">Hello</h1>
                        <p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor enim ex
                            exercitationem laboriosam nihil numquam tempora, vitae voluptates. Dolores, maxime!</p>
                    </div>
                </div>
            </div>
            <div class="carousel-item carousel-image-2 active">
                    <div class="carousel-caption mb-5">
                        <h1 class="display-3">Miami</h1>
                        <p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor enim ex
                            exercitationem laboriosam nihil.</p>
                        <a href="#" class="btn btn-primary btn-lg">Learn more</a>
                    </div>
            </div>
            <div class="carousel-item carousel-image-3">
                <div class="container">
                    <div class="carousel-caption text-right mb-5">
                        <h1 class="display-3">Hello</h1>
                        <p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolor enim ex
                            exercitationem laboriosam nihil numquam tempora, vitae voluptates. Dolores, maxime!</p>
                    </div>
                </div>
            </div>
        </div>
        <a href="#myCarousel" data-slide="prev" class="carousel-control-prev">
            <span class="carousel-control-prev-icon"></span>
        </a>
        <a href="#myCarousel" data-slide="next" class="carousel-control-next">
            <span class="carousel-control-next-icon"></span>
        </a>
    </div>

Answer №1

To achieve the desired effect, adjusting the TranslateY property and overriding the Bootstrap bottom position should do the trick. Additionally, it is recommended to eliminate the containers.

.carousel-caption {
  transform: translateY(-50%);
  bottom: 0;
  top: 50%;
}

Explore this link for more information.

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

Ways to incorporate the setTimeOut function

<body> <script> $(window).scroll(function() { $('#csgo').each(function(){ var imagePos = $(this).offset().top; var topOfWindow = $(window).scroll ...

Exploring IndexedDB with Multi-dimensional Relationships

How do you manage many-to-many relationships in IndexedDB systems? For instance, let's consider a scenario where there is a Blog object to represent a blog post and a Tag object for tagging the posts. A single Blog can have multiple tags, and each ta ...

The AJAX POST request is not receiving the JSON data as expected

After creating an HTML form with the following structure: <form id="loginForm" name="loginForm"> <div class="form-group"> <input type="username" class="form-control" id="username" name="username" placeholder="Your username..." > ...

Copying and pasting seems to be causing issues with the functionality of modals and collapsing on Bootstrap

I'm encountering an issue with Bootstrap. After copying and pasting a page that had a modal and a collapse feature, the functionality no longer works on the copied page. However, it works perfectly on the original page. Any idea why this might be happ ...

Button-operated lightbox image slider

I am currently developing a website on WAMP where users can store images and view them in a lightbox effect. I have successfully implemented the lightbox effect, but I am facing challenges with moving between images within the lightbox. <html> <? ...

Are you interested in designing a bootstrap album for your homepage?

I'm currently working on designing an album-style layout similar to the examples provided below: if you look at the recent works section where you have an image on one side and text on the other, occupying the entire width of the page: or the example ...

Having issues with email verification and the length of phone numbers not functioning properly

I need to validate two text fields before registration: the email must be in correct format and the number must have exactly 11 digits. Any mismatches should trigger an error message. For the email validation, I used a function that checks for the require ...

Navigating the rollout of a fresh new design

When implementing a new design on a website, how can you bypass the need for users to clear their browser cache in order to see the updated changes? Is there a way to automatically refresh the cache once a new version of the website is uploaded, or are th ...

Breaking an array in JavaScript

I'm developing a pure JavaScript hangman game and facing an issue with splitting words from an array into single letters. When I split the array, I get "," for every letter. For example, when I split the word [station], it returns "s,t,a,t,i,o,n". M ...

The visibility of the eye icon on the password field may vary, occasionally appearing and disappearing from view

Here is the code for my login form password field (I'm using bootstrap 4): <div class="form-account-label-input"> <label> Password <span class="star-red">&nbsp;*</span></label> <input type ...

Mega Dropdown Menu using CSS

I am currently working on a dynamic mega drop-down menu using only HTML and CSS. The issue I'm facing is that when I select one of the list items (LIs), it expands in size at the expense of the other LIs. I'm not sure where the problem lies, so ...

Is there a way to distinguish the navigation bar list from the body list?

Currently, I am in the process of developing a website with Django 1.9 and manually coding all the HTML components. However, I am facing some challenges. One of the elements I created is the navigation bar, for which I utilized the following HTML code: h ...

What is the process for assigning the value returned from an Angular HTTP request to ng-bind?

I am trying to retrieve a value from an HTTP request in AngularJS and set it as the result in a variable that is bound to ng-bind. The goal is for the value returned from the HTTP request to be displayed when text is typed into an input field. Below is th ...

Discover the position of a dynamically added element

Is there a way to identify the specific dynamically added checkbox that was clicked, whether by index or name? I came across a similar question with a solution in this JSFiddle: JSFiddle Instead of just displaying "clicked", I would like it to show someth ...

"Need help with resolving issues in my React Bootstrap Navbar? Learn the latest updates on fixing Navbar Brand Collapse here

Having issues with my React.js website navbar created using bootstrap. The menu button doesn't show up when the navbar collapses at a certain point. Can someone spot what's missing in the code below? Tried toggling by following a tutorial, but i ...

Creating a dynamic layout with Bootstrap 4 featuring a full-page design, two columns, and a

For a simple "login" page, I came across this template: HTML: <div class="d-flex align-items-center flex-column justify-content-center h-100 bg-dark text-white" id="header"> <h1 class="display-4">Hello.</h1 ...

What causes child elements to contribute padding to the parent element when using CSS float?

While working on a website coding project, I encountered a puzzling issue. The layout consists of two columns with float: left, along with margin: 0 and padding: 0. Within these columns are blocks. When the blocks are empty, everything seems fine, and I c ...

I noticed that my CSS style sheet is only working on three of my pages. What should I do to make sure it affects the fourth page as well?

I am currently facing an issue with my website where I have linked one .css stylesheet to 3 different pages. This is just a temporary template until I finalize the individual look of each page. After performing some div positioning on the site, most pages ...

Transferring information from template to associated component

Is it possible to transfer data from a template to a component without the need for an event trigger like a button or form submission? For instance, in the code snippet provided, how can we pass the 'item' from the 'items' array to the ...

Incorporating pre-designed elements into the bottom section of my

I'm currently facing an issue while trying to integrate a footer content from a template into my slideout footer. The problem is that the template footer is currently spanning across the entire width of the page, and I am struggling to contain it with ...