<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CodePen - Material Like User Registration Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Quattrocento+Sans" rel="stylesheet"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
<div class="form-card">
<div class="avatar"></div>
<form class="material">
<div class="material-input">
<label>Username</label>
<input type="text"/>
</div>
<div class="material-input">
<label>Email</label>
<input type="text"/>
</div>
<div class="material-input">
<label>Password</label>
<input type="password"/>
</div>
<div class="material-input">
<label>Confirm Password</label>
<input type="password"/>
</div>
</form>
<div class="buttons">
<button class="cancel">Cancel</button>
<button class="update">Create Account</button>
</div>
</div>
<!-- partial -->
<script src="./script.js"></script>
</body>
</html>
body {
font-family: "Quattrocento Sans", sans-serif;
font-size: 16px;
width: 100%;
height: 100%;
min-height: 100vh;
display: -webkit-box;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
background-image: linear-gradient(30deg, RoyalBlue, pink);
background-size: cover;
}
.form-card {
background: white;
padding: 4rem 2rem;
width: 60%;
max-width: 460px;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
position: relative;
border-radius: 12px;
margin-top: 30px;
}
@media only screen and (max-width: 680px) {
.form-card {
width: 70%;
}
}
.avatar {
position: absolute;
top: -50px;
left: 50%;
width: 100px;
height: 100px;
background: white;
margin-left: -60px;
box-shadow: 0 12px 12px rgba(0, 0, 0, 0.25);
border: 5px solid white;
border-radius: 50%;
background-image: url("https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=200&fit=max&s=707b9c33066bf8808c934c8ab394dff6");
background-position: center -18px;
background-repeat: no-repeat;
background-size: 110px;
}
form.material {
position: relative;
padding-bottom: 40px;
}
.material-input {
position: relative;
padding-top: 20px;
-webkit-transition: all 0.15s ease-out;
transition: all 0.15s ease-out;
width: 90%;
margin: 0 auto 20px;
}
.material-input label {
position: absolute;
pointer-events: none;
left: 4px;
top: 26px;
color: darkgray;
-webkit-transform: scale(1.1);
transform: scale(1.1);
-webkit-transition: all 0.15s ease-out;
transition: all 0.15s ease-out;
}
.material-input input {
border: none;
width: 100%;
color: #363636;
border-bottom: 2px solid darkgray;
padding: 6px 4px;
outline: none;
-webkit-transition: all 0.15s ease-out;
transition: all 0.15s ease-out;
}
.material-input.materialize input {
border-bottom: 2px solid crimson;
}
.material-input.materialize label {
top: 0;
left: 0;
color: crimson;
-webkit-transform: scale(0.95);
transform: scale(0.95);
}
.buttons {
position: absolute;
width: 100%;
bottom: 0;
left: 0;
display: -webkit-box;
display: flex;
-webkit-box-pack: justify;
justify-content: space-between;
}
.buttons button {
padding: 20px;
margin: 0;
width: 50%;
color: white;
text-shadow: 0 0 8px rgba(0, 0, 0, 0.5);
border: none;
cursor: pointer;
-webkit-transition: all 0.25s ease-in-out;
transition: all 0.25s ease-in-out;
}
.buttons button.cancel {
background: Crimson;
border-bottom-left-radius: 8px;
}
.buttons button.cancel:hover {
background: #be324e;
}
.buttons button.update {
background: LimeGreen;
border-bottom-right-radius: 8px;
}
.buttons button.update:hover {
background: #52ad52;
}
const form = document.querySelector('form');
const materialInputs = form.querySelectorAll('.material-input > input');
function materialize() {
this.parentElement.classList.add('materialize');
}
function dematerialize() {
if (this.value === '')
this.parentElement.classList.remove('materialize');
}
materialInputs.forEach(input => {
input.addEventListener("focus", materialize);
input.addEventListener("blur", dematerialize);
});