Search code examples
twitter-bootstrapcarousel

What is the best practice on how to align vertically testimonials in slider


I'm trying to create a testimonials carousel slider with text only The testimonial text is aligning at the top of the div, unable to align text vertically in the center.

    <div class="container">
        <div id="carouselContent" class="carousel slide" data-ride="carousel">
        <ol class="carousel-indicators">
            <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
            <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
            <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
        </ol>
            <div class="carousel-inner">
                <div class="carousel-item active text-center">
                    <p>Testimonial 1</p>
                </div>
                <div class="carousel-item text-center">
                    <p>Testimonial 2</p>
                </div>
                <div class="carousel-item text-center">
                    <p>Testimonial 3</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>
    </div>
</section>

#carouselContent{
  height: 200px;

}

.container {
  background-color: blue;
  color: white;
} 

Expecting testimonial to align vertically in the center but now align at the top of the div.

Solution

  • Finally, found the solution:

            <div id="carouselContent" class="carousel slide text-center d-flex align-items-center" data-ride="carousel">
            <ol class="carousel-indicators">
                <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
                <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
            </ol>
                <div class="carousel-inner">
                    <div class="carousel-item active text-center">
                        <p>Testimonial 1</p>
                    </div>
                    <div class="carousel-item text-center">
                        <p>Testimonial 2</p>
                    </div>
                    <div class="carousel-item text-center">
                        <p>Testimonial 3</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>
        </div>
    </section>
    
    #carouselContent{
      height: 200px;
    
    }
    
    .container {
      background-color: blue;
      color: white;
    }