A Pen by Ulises Mariano Melgarejo on CodePen.
Created
November 27, 2020 23:35
-
-
Save Nemo3003/7752f34b80dc313db128aa084f1a6b7a to your computer and use it in GitHub Desktop.
NWRWQJB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="header"> | |
<h2>Create Account</h2> | |
</div> | |
<form id="form" class="form"> | |
<div class="form-control"> | |
<label for="username">Username</label> | |
<input type="text" placeholder="Ulises" id="username" /> | |
<i class="fas fa-check-circle"></i> | |
<i class="fas fa-exclamation-circle"></i> | |
<small>Error message</small> | |
</div> | |
<div class="form-control"> | |
<label for="username">Email</label> | |
<input type="email" placeholder="[email protected]" id="email" /> | |
<i class="fas fa-check-circle"></i> | |
<i class="fas fa-exclamation-circle"></i> | |
<small>Error message</small> | |
</div> | |
<div class="form-control"> | |
<label for="username">Password</label> | |
<input type="password" placeholder="Password" id="password"/> | |
<i class="fas fa-check-circle"></i> | |
<i class="fas fa-exclamation-circle"></i> | |
<small>Error message</small> | |
</div> | |
<div class="form-control"> | |
<label for="username">Password check</label> | |
<input type="password" placeholder="Password two" id="password2"/> | |
<i class="fas fa-check-circle"></i> | |
<i class="fas fa-exclamation-circle"></i> | |
<small>Error message</small> | |
</div> | |
<button>Submit</button> | |
</form> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const form = document.getElementById('form'); | |
const username = document.getElementById('username'); | |
const email = document.getElementById('email'); | |
const password = document.getElementById('password'); | |
const password2 = document.getElementById('password2'); | |
form.addEventListener('submit', e => { | |
e.preventDefault(); | |
checkInputs(); | |
}); | |
function checkInputs() { | |
// trim to remove the whitespaces | |
const usernameValue = username.value.trim(); | |
const emailValue = email.value.trim(); | |
const passwordValue = password.value.trim(); | |
const password2Value = password2.value.trim(); | |
if(usernameValue === '') { | |
setErrorFor(username, 'Username cannot be blank'); | |
} else { | |
setSuccessFor(username); | |
} | |
if(emailValue === '') { | |
setErrorFor(email, 'Email cannot be blank'); | |
} else if (!isEmail(emailValue)) { | |
setErrorFor(email, 'Not a valid email'); | |
} else { | |
setSuccessFor(email); | |
} | |
if(passwordValue === '') { | |
setErrorFor(password, 'Password cannot be blank'); | |
} else { | |
setSuccessFor(password); | |
} | |
if(password2Value === '') { | |
setErrorFor(password2, 'Password2 cannot be blank'); | |
} else if(passwordValue !== password2Value) { | |
setErrorFor(password2, 'Passwords does not match'); | |
} else{ | |
setSuccessFor(password2); | |
} | |
} | |
function setErrorFor(input, message) { | |
const formControl = input.parentElement; | |
const small = formControl.querySelector('small'); | |
formControl.className = 'form-control error'; | |
small.innerText = message; | |
} | |
function setSuccessFor(input) { | |
const formControl = input.parentElement; | |
formControl.className = 'form-control success'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@import url("https://fonts.googleapis.com/css2?family=Castoro:ital@0;1&display=swap") | |
* { | |
box-sizing: border-box; | |
} | |
body { | |
background-color: #9b59b6; | |
font-family: 'Castoro', sans-serif; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
min-height: 100vh; | |
margin: 0; | |
} | |
.container { | |
background-color: #fff; | |
border-radius: 5px; | |
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); | |
overflow: hidden; | |
width: 400px; | |
max-width: 100%; | |
} | |
.header { | |
border-bottom: 1px solid #f0f0f0; | |
background-color: #f7f7f7; | |
padding: 20px 40px; | |
} | |
.header h2 { | |
margin: 0; | |
} | |
.form { | |
padding: 30px 40px; | |
} | |
.form-control { | |
margin-bottom: 10px; | |
padding-bottom: 20px; | |
position: relative; | |
} | |
.form-control label { | |
display: inline-block; | |
margin-bottom: 5px; | |
} | |
.form-control input { | |
border: 2px solid #f0f0f0; | |
border-radius: 4px; | |
display: block; | |
font-family: inherit; | |
font-size: 14px; | |
padding: 10px; | |
width: 100%; | |
} | |
.form-control input:focus { | |
outline: 0; | |
border-color: #777; | |
} | |
.form-control.success input { | |
border-color: #2ecc71; | |
} | |
.form-control.error input { | |
border-color: #e74c3c; | |
} | |
.form-control i { | |
visibility: hidden; | |
position: absolute; | |
top: 40px; | |
right: 10px; | |
} | |
.form-control.success i.fa-check-circle { | |
color: #2ecc71; | |
visibility: visible; | |
} | |
.form-control.error i.fa-exclamation-circle { | |
color: #e74c3c; | |
visibility: visible; | |
} | |
.form-control small { | |
color: #e74c3c; | |
position: absolute; | |
bottom: 0; | |
left: 0; | |
visibility: hidden; | |
} | |
.form-control.error small { | |
visibility: visible; | |
} | |
.form button { | |
background-color: #8e44ad; | |
border: 2px solid #8e44ad; | |
border-radius: 4px; | |
color: #fff; | |
display: block; | |
font-family: inherit; | |
font-size: 16px; | |
padding: 10px; | |
margin-top: 20px; | |
width: 100%; | |
} | |
/* SOCIAL PANEL CSS */ | |
.social-panel-container { | |
position: fixed; | |
right: 0; | |
bottom: 80px; | |
transform: translateX(100%); | |
transition: transform 0.4s ease-in-out; | |
} | |
.social-panel-container.visible { | |
transform: translateX(-10px); | |
} | |
.social-panel { | |
background-color: #fff; | |
border-radius: 16px; | |
box-shadow: 0 16px 31px -17px rgba(0,31,97,0.6); | |
border: 5px solid #001F61; | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
font-family: 'Muli'; | |
position: relative; | |
height: 169px; | |
width: 370px; | |
max-width: calc(100% - 10px); | |
} | |
.social-panel button.close-btn { | |
border: 0; | |
color: #97A5CE; | |
cursor: pointer; | |
font-size: 20px; | |
position: absolute; | |
top: 5px; | |
right: 5px; | |
} | |
.social-panel button.close-btn:focus { | |
outline: none; | |
} | |
.social-panel p { | |
background-color: #001F61; | |
border-radius: 0 0 10px 10px; | |
color: #fff; | |
font-size: 14px; | |
line-height: 18px; | |
padding: 2px 17px 6px; | |
position: absolute; | |
top: 0; | |
left: 50%; | |
margin: 0; | |
transform: translateX(-50%); | |
text-align: center; | |
width: 235px; | |
} | |
.social-panel p i { | |
margin: 0 5px; | |
} | |
.social-panel p a { | |
color: #FF7500; | |
text-decoration: none; | |
} | |
.social-panel h4 { | |
margin: 20px 0; | |
color: #97A5CE; | |
font-family: 'Muli'; | |
font-size: 14px; | |
line-height: 18px; | |
text-transform: uppercase; | |
} | |
.social-panel ul { | |
display: flex; | |
list-style-type: none; | |
padding: 0; | |
margin: 0; | |
} | |
.social-panel ul li { | |
margin: 0 10px; | |
} | |
.social-panel ul li a { | |
border: 1px solid #DCE1F2; | |
border-radius: 50%; | |
color: #001F61; | |
font-size: 20px; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 50px; | |
width: 50px; | |
text-decoration: none; | |
} | |
.social-panel ul li a:hover { | |
border-color: #FF6A00; | |
box-shadow: 0 9px 12px -9px #FF6A00; | |
} | |
.floating-btn { | |
border-radius: 26.5px; | |
background-color: #001F61; | |
border: 1px solid #001F61; | |
box-shadow: 0 16px 22px -17px #03153B; | |
color: #fff; | |
cursor: pointer; | |
font-size: 16px; | |
line-height: 20px; | |
padding: 12px 20px; | |
position: fixed; | |
bottom: 20px; | |
right: 20px; | |
z-index: 999; | |
} | |
.floating-btn:hover { | |
background-color: #ffffff; | |
color: #001F61; | |
} | |
.floating-btn:focus { | |
outline: none; | |
} | |
.floating-text { | |
background-color: #001F61; | |
border-radius: 10px 10px 0 0; | |
color: #fff; | |
font-family: 'Muli'; | |
padding: 7px 15px; | |
position: fixed; | |
bottom: 0; | |
left: 50%; | |
transform: translateX(-50%); | |
text-align: center; | |
z-index: 998; | |
} | |
.floating-text a { | |
color: #FF7500; | |
text-decoration: none; | |
} | |
@media screen and (max-width: 480px) { | |
.social-panel-container.visible { | |
transform: translateX(0px); | |
} | |
.floating-btn { | |
right: 10px; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment