Add text on top of the image in the Bootstrap carousel

I have a carousel with an image that I would like to translate the text, but it does not work. Text appears below the image instead of overlaid on top of it.

<!-- WRAPPER FOR SLIDES --> <div class="carousel-inner"> <div class="active item"> <div class="carousel-content"> <img src="img/Slide 1.jpg" alt="..." position="relative"> <p>TEST</p> </div> <div class="carousel-caption"> <h3>What we do</h3> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="carousel-caption"> <h3>What we Do</h3> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="carousel-caption"> <h3>Who we Are</h3> </div> </div> </div> 
+5
source share
3 answers

You can just position set the absolute element as inline captions and set offsets top / bottom , left / right .

Note that carousel signatures have z-index: 10 by default, so you can give a positioned element a higher z-index :

For instance:

 .carousel-content { position: absolute; bottom: 10%; left: 5%; z-index: 20; color: white; text-shadow: 0 1px 2px rgba(0,0,0,.6); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> <div id="carousel-example-generic" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li> <li data-target="#carousel-example-generic" data-slide-to="1"></li> <li data-target="#carousel-example-generic" data-slide-to="2"></li> </ol> <div class="carousel-inner"> <div class="active item"> <img src="http://lorempixel.com/1200/315" alt="..."> <div class="carousel-content"> <p>TEST</p> </div> <div class="carousel-caption"> <h3>What we do</h3> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="carousel-caption"> <h3>What we Do</h3> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="carousel-caption"> <h3>Who we Are</h3> </div> </div> </div> </div> 
+9
source

Here is a possible solution:

jsfiddle: http://jsfiddle.net/38v09vha/

  <div class="carousel-inner"> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="absolute-div"> <div class="carousel-caption"> <h3>What we Do</h3> </div> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="absolute-div"> <div class="carousel-caption"> <h3>What we Do</h3> </div> </div> </div> <div class="item"> <img src="http://placehold.it/1200x315" alt="..."> <div class="absolute-div"> <div class="carousel-caption"> <h3>What we Do</h3> </div> </div> </div> </div> 

and css:

 .carousel-caption { position: absolute; z-index: 1; display:table; width:100%; height:100%; } .absolute-div { position: absolute; top: 0; left: 0; right: 0; bottom: 0; } .carousel-caption h3 { display:table-cell; vertical-align: middle; text-align:center; } .item { position:relative; } 

Assuming you want them to be vertically aligned in the middle of the image. Basically, you'll want to relatively position the parent div with sliders, which inherits its height from the total height of the image and text. Then you need to create a div that contains the text with the css position: absolute attribute. This element will be a direct child of the positioned parent. This will allow you to fully position the text in the closest relative to the positional element. Check out this CSS Tricks tutorial to see how it works .

This will allow you to position the text above the image, then I went ahead and used the positioning of the table so that you could center them vertically, although you could go and place them in the image wherever you wanted.

+3
source

Hope this helps someone, in my case I did it with the following code:

 <style> .carousel-caption { position: absolute; z-index: 1; display:table; width:100%; height:100%; } .carousel-caption div { display:table-cell; vertical-align: middle; text-align:center; } .trickcenter { position: fixed; top: 84%; // 50% for perfect centering left: 50%; transform: translate(-50%, -50%); } </style> <div class="item"> <img src="images/slider_T02.jpg" alt="Moto de collection"> <div class="carousel-caption trickcenter"> <div>HERE THE TEXT YOU WANT</div> </div> </div> <div class="item"> <img src="images/slider_T03.jpg" alt="VΓ©hicule Haut de Gamme"> <div class="carousel-caption trickcenter"> <div>HERE THE SECOND TEXT</div> </div> </div> 
+2
source

All Articles