Being new to web development I tried making a nice login. I couldn't get the positions of the elements right and I was forced to use " background-attachment: fixed !important; ".
Is there any other way of achieving the same results {picture given below} without using ``` background-attachment: fixed !important;
Here is my code:
body {
margin: 0;
padding: 0;
font-family: sans-serif;
height: 100%;
background: linear-gradient( red, green);
background-attachment: fixed !important;
}
.box {
width: 300px;
padding: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: #191919;
text-align: center;
}
.box h1 {
color: white;
text-transform: uppercase;
font-weight: 500;
}
.box input[type="text"],
.box input[type="password"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 10px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
}
.box input[type="text"]:focus,
.box input[type="password"]:focus {
width: 280px;
border-color: #2ecc71;
}
.box input[type="submit"] {
border: 0;
background: none;
display: block;
margin: 20px auto;
text-align: center;
border: 2px solid #3498db;
padding: 14px 40px;
width: 200px;
outline: none;
color: white;
border-radius: 24px;
transition: 0.25s;
cursor: pointer;
}
.box input[type="submit"]:hover {
background: #2ecc71;
}
<form class="box" action="index.html" method="POST">
<h1>Login</h1>
<input type="text" name="" placeholder="Username">
<input type="password" name="" placeholder="password">
<input type="submit" name="" value="Login">
</form>
I googled a lot to find a good solution for this simple problem, but got more confused, so I want some experience person's advice on this, and do's and don't as a beginner.
{ For the Ans, I would be grateful if you could put the whole code and explain why you chose a particular style and how it resolves the general problem ( I read that using "background-attachment: fixed !important; " might cause trouble) } Thankyou.
----------------------- After Edits ----------------------------------
The Problem here is, without " background-attachment: fixed !important; " the background gradient doesn't work. and if I put position as relative for the "box" element, the result is different than what I want.
So, I want the positions correct {as per the Image }, with Background gradient, and without background-attachment: fixed !important;