-1

I am trying to place the input field at the center of the page, any help. So far i have only been able to center the contents horizontal, the vertical centering has failed.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
           display: flex;
           align-items: center;
           justify-content: center; 
        }
        input[type=text] {
            margin: 0;
        }

        form {
            border: 1px solid blue;
        }
    </style>
</head>
<body>
    <div class="container">
        <form action="">
            <input type="text">
        </form>
    </div>
</body>
</html>
KevinCK
  • 415
  • 3
  • 10

1 Answers1

0

You need to set the containers height:

.container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

input[type=text] {
  margin: 0;
}

form {
  border: 1px solid blue;
}
<div class="container">
  <form action="">
    <input type="text">
  </form>
</div>
Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49