bootstrap-4twitter-bootstrap-4

Text only carousel


I am unable to have a carousel with only text without any img. The text seems to be colliding with the controls. Every example I've found uses the <img>. I have tried to use d-flex class, block and even the carousel-caption. Nothing has worked so far.

<div id="carouselContent" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner" role="listbox">
        <div class="carousel-item active">
            <p>lorem ipsum (imagine longer text)</p>
        </div>
        <div class="carousel-item">
            <p>lorem ipsum (imagine longer text)</p>
        </div>
    </div>
    <a class="carousel-control-prev" href="#carouselContent" role="button" 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="#carouselContent" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
</div>

Solution

  • I think the carousel-controls are designed to overlay the content, whether it's text or images. It would seem that text-center would be a good option to center the text of each item.

    However, as of BS alpha 6, the .carousel-item is display:flex; which limits some of the positioning you can do with the contents of carousel-item. There is an open issue for this: https://github.com/twbs/bootstrap/issues/21611

    As a workaround, you could use text-center and override display:block for the active carousel item:

     <div class="carousel-item text-center p-4">
           <p>lorem ipsum (imagine longer text)</p>
     </div>
    
    .carousel-item.active {
        display:block;
    }
    

    Demo: http://www.codeply.com/go/OJHdvdXimm


    Also see: Vertically center text in Bootstrap carousel