I'm facing a challenge in setting the login container at the center of the screen while occupying the remaining height. It seems that using justify-content
aligns the content in the center, but despite setting the container's height to 100%
, align-items: center
does not work in this scenario.
I've also attempted to set the body's height to 100%, but encountered issues with overflow when resizing the window and some scrolling in fullscreen mode, which is undesirable.
I am currently utilizing tailwindcss for styling, although I have tried replicating the issue in custom CSS without success.
Is there a solution to rectify this? I simply aim to achieve a design similar to the Google login page experience.
html {
height: 100%;
}
body {
min-height: 100%;
overflow-x: hidden;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"⌋
<title>Document</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="antialiased text-slate-400 bg-slate-900">
<div class="h-full">
<!-- Navbar -->
<nav
class="w-full flex justify-between items-center px-10 py-4 border-b border-b-slate-700">
<a href="/" class="relative text-3xl text-slate-200 font-bold tracking-wider" >Navbar</a>
<ul class="flex gap-5 cursor-pointer">
<li>
<a href="/" class="px-4 py-2 border border-transparent font-semibold rounded-lg duration-100" >Home</a>
</li>
<li>
<a href="/login" class="px-4 py-2 border border-transparent font-semibold rounded-lg duration-100">Login</a></li>
</ul>
</nav>
<!-- Login -->
<div class="h-full flex justify-center items-center">
<div class="w-[350px] flex flex-col justify-center items-center space-y-10 px-10 py-10 border border-slate-700/50 shadow-lg rounded-lg">
<h3 class="mb-5 flex justify-center items-center text-2xl font-bold text-sky-500 cursor-default">Login</h3>
<form class="flex flex-col justify-center gap-3">
<label for="username" class="font-semibold">Username</label>
<input
type="text"
name="username"
id="username"
class="outline-none bg-sky-600/10 px-4 py-2 rounded-md font-semibold text-slate-300 placeholder:text-sm placeholder:font-semibold"
placeholder="Enter your username"
/>
<label for="password" class="font-semibold">Password</label>
<input
type="password"
name="password"
id="password"
class="outline-none bg-sky-600/10 px-4 py-2 rounded-md font-semibold text-slate-300 placeholder:text-sm placeholder:font-semibold"
placeholder="Enter your password"
/>
<div class="w-full flex flex-col justify-center items-center gap-5 mt-10">>
<button class="w-full px-5 py-2 bg-sky-500 rounded-full font-semibold text-white hover:bg-sky-500/80 duration-300">Login</button>
<a href="/register" class="w-full px-5 py-2 bg-green-500 rounded-full font-semibold text-white text-center hover:bg-green-500/80 duration-300">Create an account</a >
</div>
</form>
</div>
</div>
</div>
</body>
</html>