Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically center text in Bootstrap carousel

I have trouble creating a carousel in Bootstrap 4 with text centered both horizontally and vertically.

I have created the bootply with a carousel, but the text is just in the upper left corner instead of in the middle of the screen.

<div class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <h1>Text 1</h1>
    </div>
    <div class="carousel-item">
      <h1>Text 2</h1>
    </div>
    <div class="carousel-item">
      <h1>Text 3</h1>
    </div>´
  </div>
</div>
like image 953
Jamgreen Avatar asked Aug 28 '17 08:08

Jamgreen


1 Answers

You can use the Bootstrap 4 utility classes (no additional CSS is needed)...

https://www.codeply.com/go/ORkdymGWzM

<div class="carousel slide" data-ride="carousel">
    <div class="carousel-inner text-center">
        <div class="carousel-item active">
            <div class="d-flex h-100 align-items-center justify-content-center">
                <h1>Text 1</h1>
            </div>
        </div>
        <div class="carousel-item">
            <div class="d-flex h-100 align-items-center justify-content-center">
                <h1>Text 2</h1>
            </div>
        </div>
        <div class="carousel-item">
            <div class="d-flex h-100 align-items-center justify-content-center">
                <h1>Text 3</h1>
            </div>
        </div>
    </div>
</div>
like image 134
Zim Avatar answered Oct 20 '22 20:10

Zim