-1

I want to align the card into center vertically

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="container" style="width: 100%;height: 100vh">
  <div class="row ">
    <div class="col-md-6 offset-md-3">
      <div class="card">
        <h1>hello</h1>
      </div>
    </div>
  </div>
</div>

The container has height: 100vh; and width:100%;

Kareem Dabbeet
  • 3,838
  • 3
  • 16
  • 34

4 Answers4

1

Try using bootstrap class names: d-flex align-items-center justify-content-center inside your container div class

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<div class="container d-flex align-items-center justify-content-center" style="width: 100%; height: 100vh;">
        <div class="row">
            <div class="col-md-6 offset-md-3">
                <div class="card">
                    <h1>hello</h1>
                </div>
            </div>
        </div>
    </div>
Kirubel
  • 1,461
  • 1
  • 14
  • 33
1

Use d-flex align-items-center class in Bootstrap

Your h1 have a margin-bottom so it can show not align vertically it remove by add mb-0 to h1

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="container d-flex align-items-center" style="width: 100%;height: 100vh">
  <div class="row w-100">
    <div class="col-md-6 offset-md-3">
      <div class="card">
        <h1 class="mb-0">hello</h1>
      </div>
    </div>
  </div>
</div>
Rayees AC
  • 4,426
  • 3
  • 8
  • 31
0

you want to vertically align a element in the center or middle, you can simply apply the class align-items-center on the containing element.

Huzee
  • 114
  • 7
0

make container as flex and add align-items-center to center items vertically

to make sure that the row will remains full width add: w-100 class to the row

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="container d-flex align-items-center justify-content-center" style="width: 100%;height: 100vh">
  <div class="row w-100">
    <div class="col-md-6 offset-md-3">
      <div class="card">
        <h1>hello</h1>
      </div>
    </div>
  </div>
</div>
Kareem Dabbeet
  • 3,838
  • 3
  • 16
  • 34