Search code examples
ionic-frameworkionic4

vertically centered row in ionic 4


I'm using Ionic version 4 and I want my login form in the application to be vertically centered.

I've tried many solutions present in stack overflow but looks like all works for Ionic version 3 and also tried some of the CSS tricks like margin 0 auto; and

display:flex;
justify-content:center !important;
align-content:center !important;

But didn't work for me.

enter image description here

This is how my forms looks like, I'm using bootstrap additionally and have no custom css classes added into the template.

Here's my template code.

<ion-content color="light">
  <ion-grid>
    <ion-row class="ion-justify-content-center">
      <ion-col size-xs="9" size-md="9">
        <form>
            <div class="form-group">
              <input
                type="text"
                class="form-control"
                placeholder="Enter AccountID"
                autocomplete="off"
              />
            </div>
            <div class="form-group">
              <input
                type="email"
                class="form-control"
                placeholder="Enter Email"
                autocomplete="off"
              />
            </div>
            <div class="form-group">
              <input
                type="password"
                class="form-control"
                placeholder="Enter Password"
                autocomplete="off"
              />
            </div>
            <button type="submit" class="btn btn-primary btn-block">Submit</button>
        </form>
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

Solution

  • I did it using this styles

    ion-grid{
        height: 100%;
    }
    ion-row{
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100%;
    }