Bashar Altakrouri
Bashar Altakrouri

Reputation: 10605

How to align an ion-card in middle of the screen (vertically and horizontally) for iOS and Android?

How to align an ion-card in middle of the screen (vertically and horizontally)?

Debugging on iOS simulator displays the card but with more margin on the left side than the right. So not really centred. To center correctly i had to left: 47.5%; instead of left: 50%

Upvotes: 1

Views: 8825

Answers (3)

DJ MixRhymez
DJ MixRhymez

Reputation: 40

.error { width: 50%; height: auto; margin: auto; }

Upvotes: 2

Omkar
Omkar

Reputation: 3100

IMO check your css it should be

    .error {

 transform: translateX(-50%) translateY(-50%);
    top: 50%;
    left: 50%;
    position: absolute;
     } // close here

.error-header {
  position: relative;
  text-align: center;
  top: 36%;
  font-size: 3.0em;
  width: 100%;
  font-weight: bold;
  color: red;
}

.error-body {
  font-size: 1.0em;
  text-align: center;
  position: relative;
  top: 52%;
   width: 100%;
}

// not here

also if don't know size of card then make position fixed like try

   .error {

 transform: translateX(-50%) translateY(-50%);
    top: 50%;
    left: 50%;
    position: fixed;
     }

if you set fixed position then try

 .error {

 transform: translateX(-50%) translateY(-50%);
    top: 50%;
    left: 50%;
    position: absolute;
    margin-top: -50px;
    margin-left: -50px;
    width: 100px;
    height: 100px;
     }

OR

better you may go through this

Upvotes: 4

Sonia
Sonia

Reputation: 1919

You need to add the XY co-ordinates in one line

transform: translate(-50%, -50%);

Upvotes: 0

Related Questions