I'd like to have a horizontally and vertically centered content on one of my webpage. I've done it like this.
<!DOCTYPE html>
<html>
<head>
<title>Eko</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<div class="login-container">
<h1>Hello</h1>
</div>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</body>
</html>
And this is my CSS.
.login-container {
display: flex;
justify-content: center;
align-items: center;
}
However, the vertical center doesn't occur (just the horizontal). It works when I apply this CSS.
body {
display: flex;
justify-content: center;
align-items: center;
}
Why does it only work when we have it applied to body?