I am attempting to center the login box on the screen, but when using position: absolute
the background color changes to white.
/* all */
.patua_font {
font-family: 'Patua One', cursive;
}
.Roboto_font {
font-family: 'Roboto', sans-serif;
}
/* login css */
.cus_body {
height: 100%;
background: linear-gradient(to right, #31E89F, #00aff4); /*this has no effect after setting position absolute in box*/
}
.btn-primary.custom-btn {
background-color: #00bcd4;
border-color: #31E89F;
width: 100%;
}
.center1 {
text-align: center;
}
.cus_loginpad {
padding: 4% 7%;
}
.box {
background-color: #FAFAFA;
width: 40%;
min-width: 390px;
height: auto;
transform: translate(-50%, -50%);
left: 50%;
top: 45%;
padding: 20px 20px;
position: absolute;
border-radius: 5px;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
margin: 10px;
}
.box input {
width: 100%;
margin: 4px 0;
padding: 10px;
outline: none;
border-radius: 5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>sample</title>
<link href="https://fonts.googleapis.com/css2?family=Patua+One&family=Roboto&display=swap" rel="stylesheet">
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85f5eaf5f5e0f7abeff6c5b4abb4b3abb5">[email protected]</a>/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body class="cus_body patua_font">
<div class="container">
<div class="box ">
<div class="cus_loginpad ">
<h2 class="center1"><img src="images/sample.png" width="150" /></h2>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
</div>
<div class="form-group">
<label for="pwd">Password</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pswd">
</div>
<button type="submit" class="btn btn-primary custom-btn"> Login </button>
</div>
</div>
</div>
</body>
</html>
Is there a way to keep the background: linear-gradient(to right, #31E89F, #00aff4) while centering the login box? Thank you.