Animacion Input
by Slee
HTML
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Animaciòn a un Input con Html y Css | SLee Dw</title>
<link rel="stylesheet" href="estilos.css">
</head>
<body>
<form class="form">
<input type="text" required>
<label class="lbl-nombre">
<span class="text-nomb">Nombre</span>
</label>
</form>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css?family=Open+Sans&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Open Sans', sans-serif;
}
body{
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #0b1721;
}
.form{
width: 100%;
height: 50px;
max-width: 400px;
position: relative;
overflow: hidden;
}
.form input{
width: 100%;
height: 100%;
background: none;
color: #fff;
padding-top: 20px;
border: none;
outline: 0px;
}
.form .lbl-nombre{
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
border-bottom: 1px solid #c7c7c7;
}
.form .lbl-nombre:after{
content: '';
position: absolute;
left: 0;
bottom: -1px;
width: 100%;
height: 100%;
border-bottom: 3px solid #2ecece;
transform: translateX(-100%);
transition: all 0.3s ease;
}
.text-nomb{
position: absolute;
bottom: 5px;
left: 0;
transition: all 0.3s ease;
color: #fff;
}
.form input:focus + .lbl-nombre .text-nomb,.form input:valid + .lbl-nombre .text-nomb{
transform: translateY(-150%);
font-size: 14px;
color: #2ecece;
}
.form input:focus + .lbl-nombre:after, .form input:valid + .lbl-nombre:after{
transform: translateX(0%);
}
@media only screen and (min-width:320px) and (max-width:768px){
.form{
width:85%;
}
}