-1

I have a div for login form .I want to align the div horizontally and vertically centered in all devices.Any help is appreciated

dockerrrr
  • 277
  • 1
  • 5
  • 17

3 Answers3

13

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}
<div class="container">
  <form>
    <input type="text">
  </form>
</div>
Gerard
  • 15,418
  • 5
  • 30
  • 52
1

Try the following:

html body {
    height:100vh;
}

html body .login-box {
    width: 460px;
    height: 500px;
    margin: 0 auto;
    background: #000;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -230px;
    margin-top: -250px;
}

Please note the height and margin top is half of the height, Also the width is half of the margin left. in case you want to change the width and height of your div.

0

How about this: https://jsfiddle.net/b7b954ox/1/

Your box must have width and height so you can use:

position: fixed; /* or absolute */
left: 0;
right: 0;
top: 0;
bottom: 0;
Dejan Munjiza
  • 790
  • 1
  • 12
  • 23