Search code examples
htmlcssmobilealignmentvertical-alignment

Incorrect CSS behavior on mobile devices


I'm trying to align my login and register panel in the middle of the screen. It works fine if I check it from pc and from the inspect menu where you can select any mobiles to see if it works fine. I wanted to check it from my real mobile but this is what I get: image and this is how it looks like from the inspect menu on pc: image2

The code I use:

<div class="wrapper2" style="font-size: 24px;">
        <h2>Bejelentkezés</h2>
        <p style="padding-bottom: 30px;">Kérem töltse ki az alábbi mezőket.</p>
        <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
          <div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
            <label>Felhasználónév/Email cím</label>
            <input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
            <span class="help-block" style="color: red;"><?php echo $username_err; ?></span>
          </div>
          <div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
            <label>Jelszó</label>
            <input type="password" name="password" class="form-control">
            <span class="help-block" style="color: red;"><?php echo $password_err; ?></span>
          </div>
          <div class="form-group">
            <input type="submit" class="btn btn-primary" value="Bejelentkezés">
          </div>
          <div class="plus" style="font-size: 18px;">
          <p>Még nem regisztrált? <a href="register.php">Regisztráció</a></p>
          <p>Elfelejtette jelszavát? <a href="password-reminder.php">Jelszó emlékeztető</a></p>
          </div>
        </form>
      </div>

and the css:

.wrapper2{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font: 18px sans-serif;
  text-align: center;
}

Solution

  • Guessing by the css of div with class .wrapper2 I think you are trying to position this div vertically centered to its parent div with class .main-panel, so I checked the css of that div from live link you provided and it is 100%( I assume you want this to be equal to height of device viewport) , so you can achieve this by setting the min-height:100vh; for this div, like

    .perfect-scrollbar-on .main-panel {
        height: 100%;
        max-height: 100%;
        min-height: 100vh;
    }
    

    Hope this solves your problem.