What is the best way to show carousel captions at the top?

I am looking to enhance my bootstrap 4 carousel by displaying the carousel caption on top instead of at the bottom, similar to the example below.

https://i.sstatic.net/v2B5o.png

update: HERE IS JSFIDLE WITH FULL CODE

carousel demo

Here is the progress I have made so far:

HTML

<div class="modal fade" id="myModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <div class="pull-left">My Gallery Title</div>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                  </button>
            </div>
            <div class="modal-body">
                <div id="demo" class="carousel slide" data-ride="carousel">

                    <!-- Indicators -->
                    <ul class="carousel-indicators">
                      <li data-target="#demo" data-slide-to="0" class="active"></li>
                      <li data-target="#demo" data-slide-to="1"></li>
                      <li data-target="#demo" data-slide-to="2"></li>
                    </ul>

                    <!-- The slideshow -->
                    <div class="carousel-inner">
                      <div class="carousel-item active">
                            <div class="carousel-caption">
                                    <h3>Heading 1</h3>
                                    </div>
                        <img src="https://placeimg.com/600/400/nature/1" alt="Los Angeles">
                      </div>
                      <div class="carousel-item">
                            <div class="carousel-caption">
                                    <h3>Heading 2</h3>
                                    </div>
                        <img src="https://placeimg.com/600/400/nature/2" alt="Chicago">
                      </div>
                      <div class="carousel-item">
                            <div class="carousel-caption">
                                    <h3>Heading 3</h3>
                                    </div>
                        <img src="https://placeimg.com/600/400/nature/3" alt="New York">
                      </div>
                    </div>

                    <!-- Left and right controls -->
                    <a class="carousel-control-prev" href="#demo" data-slide="prev">
                      <span class="carousel-control-prev-icon"></span>
                    </a>
                    <a class="carousel-control-next" href="#demo" data-slide="next">
                      <span class="carousel-control-next-icon"></span>
                    </a>
                  </div>

            </div>
            <div class="modal-footer">
                <button class="btn-sm close" type="button" data-dismiss="modal">Close</button>
                <!--end modal-footer-->
            </div>
            <!--end modal-content-->
        </div>
        <!--end modal-dialoge-->
    </div>
    <!--end myModal-->>
</div>

CSS

.carousel-caption {
    position: absolute;
    right: 15%;
    top: -42px;
    left: 15%;
    z-index: 999999999;
    padding-top: 20px;
    padding-bottom: 20px;
    color: #fff;
    text-align: center;
}

However, with this solution, my carousel caption disappears. Can you suggest a solution to achieve the desired outcome?

Answer №1

modify css for .carousel-caption

.carousel-item .carousel-caption {
  position: static;
  padding-top: 20px;
  padding-bottom: 20px;
  text-align: center;
}

see the working demo here

Answer №2

To reposition the carousel caption to the top, adjust the top value to 0. This will move the caption above the carousel indicators. For accurate positioning, utilize inspect element to view the current position of the element in question.

Answer №3

To ensure proper alignment in the carousel, add the property relative to the div with the class ".carousel-item".

.carousel-item{
  position:relative;
}
.carousel-caption {
  position: absolute;
  top: 0;
  left: 0;
  width:100%;
  text-align:center;
  z-index: 999999999;
  padding-top: 5px;
  color: #fff;
}

For a complete demonstration, view the codepen link provided: https://codepen.io/anon/pen/bJygvj

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

Create a boundary behind the title on a see-through backdrop

How can I create a design where there is a line to the left and right of a headline? Usually, I would use border-top on the surrounding element and style the headline with some CSS properties like this: h2 { margin-top: -10px; padding: 0 5px; b ...

Elevate your designs with Bootstrap Cards featuring a clickable link. Give your

I am trying to incorporate bootstrap cards into a form without using a normal link. The intention is to send the data along with other information via POST method. However, I am facing an issue with the display. The blocks should maintain the same height, ...

Is it possible to show a specific portion of an image based on its size using only CSS?

Is there a way to use CSS to display only a specific part of an image based on its width and height? If not possible with CSS alone, would TypeScript be a solution? For example, if I have an image that is 2,434px × 1,697px inside a div that is 700x700, h ...

Troubleshooting the min-height problem with CSS in AngularJS Routing

My current setup is as follows in a basic HTML file: * { box-sizing: border-box; } html, body { height: 100%; min-height: 100%; margin: 0; } section { display: block; width: 100%; min-height: 100%; padding: 1em } .b1 { background: ...

Obtain consistent outcomes by entering identical data in both Ajax and PHP

My code takes a number input in a <textarea>, then uses AJAX to validate it randomly with PHP (using rand()). The validated number is returned along with the words correct or incorrect to a <div> in HTML. The issue is that if the same number i ...

JavaScript's `setAttribute` function appears to be malfunctioning when used in conjunction

I am currently working in ORMB and have come across an input element that looks like this <input id="charVal" class="oraInput" oraField="charVal"> I've been trying to dynamically add an oraSearch attribute using JavaScript, but it doesn't ...

Prevent users from clicking by using a CSS class in HTML and JavaScript

,hey there buddy 1° Can you help me figure out how to prevent click behavior using the CSS class? 2° I'm unable to add an ID to the HTML element, so I need to use the Class to achieve this. 3° None of my attempts have been successful so far. El ...

Implementing a line break within a JavaScript function specifically designed for formatting images

As I am not a javascript developer, the code I have been given for debugging is somewhat challenging. The issue at hand involves an iOS module where a .js CSS file has been set up and images are loading improperly, resulting in the need for horizontal scro ...

Identifying mouse proximity through processing.js

I am using processing.js for coding. I am trying to dynamically adjust the size variable so that it increases as the cursor approaches the ellipse and decreases as the cursor moves away from it. I also want to set a limit for the size, preferably between 5 ...

Ways to horizontally align CSS boxes in Internet Explorer

I am facing a challenge in aligning three CSS boxes horizontally on my webpage. I attempted to achieve this by using the webkit and mozilla box orient and align properties. -webkit-box-orient:horizontal; -webkit-box-pack:center; -webkit-box-align:center; ...

``Is there a faux pseudo element lurking within Firefox?"

I have a question regarding Firefox. I often notice some peculiar pseudo elements in the debugger tool, displayed as a rectangle with a dot inside: In this particular case, I cannot fathom why there would be a pseudo element in the middle of a list. Whe ...

Finding the total sum of values within a single column across all rows of a table

I have a table structured like this : HTML: <table> <tr><td>value1</td><td>value2</td><td>value3</td></tr> .... <tr><td>value1</td><td>value2</td><td>va ...

What is the best way to centrally position a <mat-card> on the screen using Angular 9?

* I'm struggling to center a <mat-card> on the screen, specifically within the toggle-device-toolbar. It's intended for mobile phones and I could use some guidance. I'm working with angular-material and ng-bootstrap* Here is the code ...

Add more key value pairs to another <div> element

My setup involves radio buttons attached to div elements. When a div is clicked, the information displayed on the widget updates to show the data associated with that div. I am using the Yahoo API to fetch the data in JSON format. The correct data is being ...

Using `display:table-cell` does not function correctly when set to a 100% width

I'm having an issue with aligning text vertically inside a div: display:table-cell; vertical-align: middle; While the text aligns properly, the div (which has a width of 100%) is shrinking in width. What could be causing this problem and is there a ...

Remember a MySQL query using JavaScript

For quite some time, I've been on a quest to unveil the solution to this issue that seems relatively straightforward, yet continues to elude me. The crux of the matter is my desire to "recall" a functional mysql query. With an HTML button and a span ...

Responsive Video Embed Using Bootstrap-5

I'm facing some challenges with Bootstrap responsive video embedding. It seems like the parent container is not responding to changes, only the content within the <iframe> tag is being responsive. Any idea what might be going wrong? .embed- ...

Steps for making input stand out and display full content

One of the challenges I am facing is that some of my input fields are too small to display the entire text, and unfortunately, I cannot change their size. Is there a way to display the full content of the input when hovering without disrupting the layout? ...

Utilizing jQuery to add a class to an element when a different one is hovered above

I'm currently working on implementing effects on the edges of a webpage that will be triggered when a central div is hovered over. The main tool I'm using for this task is jQuery. Despite my efforts to diagnose the issue by using alerts in my Ja ...

Element with adhesive properties alters its color at a particular location

I need the sticky element to change colors at specific points and then revert back to its original color. The color should be orange initially, green on block 2, and orange again on block 3. For the complete code and to address any issues with jQuery, pl ...