Skip to content

Instantly share code, notes, and snippets.

@Yanioconjota
Created December 11, 2018 00:08
Show Gist options
  • Save Yanioconjota/8a77b1568d2a212416cff636caf87bd6 to your computer and use it in GitHub Desktop.
Save Yanioconjota/8a77b1568d2a212416cff636caf87bd6 to your computer and use it in GitHub Desktop.
Material like inputs
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Nombre y Apellido</label>
</div>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Email</label>
</div>
<div class="group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Teléfono</label>
</div>
/* form starting stylings ------------------------------- */
.group {
margin-bottom: 25px;
position: relative;
padding-left: 16px;
}
input {
width: 100%;
font-size: 17px;
padding: 10px 10px 10px 5px;
display: block;
border: none;
border-bottom: 2px solid gray;
&:focus {
outline: none;
}
}
/* LABEL ======================================= */
label {
font-weight: normal;
position: absolute;
pointer-events: none;
left: 16px;
top: 10px;
font-size: 17px;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
}
/* active state */
input {
&:focus ~ label, &:valid ~ label {
top: -18px;
font-size: 14px;
color: orange;
}
}
/* BOTTOM BARS ================================= */
.bar {
position: relative;
display: block;
width: 100%;
&:before, &:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: orange;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
}
&:before {
left: 50%;
}
&:after {
right: 50%;
}
}
/* active state */
input:focus ~ .bar {
&:before, &:after {
width: 50%;
}
}
/* HIGHLIGHTER ================================== */
.highlight {
position: absolute;
height: 60%;
width: 100px;
top: 25%;
left: 0;
pointer-events: none;
opacity: 0.5;
}
/* active state */
input:focus ~ .highlight {
-webkit-animation: inputHighlighter 0.3s ease;
-moz-animation: inputHighlighter 0.3s ease;
animation: inputHighlighter 0.3s ease;
}
/* ANIMATIONS ================ */
@-webkit-keyframes inputHighlighter {
from {
background: orange;
}
to {
width: 0;
background: transparent;
}
}
@-moz-keyframes inputHighlighter {
from {
background: orange;
}
to {
width: 0;
background: transparent;
}
}
@keyframes inputHighlighter {
from {
background: orange;
}
to {
width: 0;
background: transparent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment