<div id="wrap" class="input">
<header class="input-header">
<h1>Input Text/Password Animation</h1>
</header>
<section class="input-content">
<h2>Input Text/Password Animation<span>Only CSS</span></h2>
<div class="input-content-wrap">
<dl class="inputbox">
<dt class="inputbox-title">Input Text</dt>
<dd class="inputbox-content">
<input id="input0" type="text" required/>
<label for="input0">ID</label>
<span class="underline"></span>
</dd>
</dl>
<dl class="inputbox">
<dt class="inputbox-title">Input Password</dt>
<dd class="inputbox-content">
<input id="input1" type="password" required/>
<label for="input1">Password</label>
<span class="underline"></span>
</dd>
</dl>
<div class="btns">
<button class="btn btn-confirm">Sign In</button>
<button class="btn btn-cancel">Cancel</button>
</div>
</div>
</section>
</div>
// color vars
$primary-color: #1a237e;
$dark-primary-color: #0f1041;
$accent-color: #2962ff;
$sub-yellow: #ffca00;
//common style
html,body{
height: 100%;
background: #e0e0e0;
font-family:sans-serif;
font-size:14px;
}
#wrap{
width: 100%;
max-width:900px;
margin:0 auto 60px;
box-shadow: 0 3px 6px rgba(0,0,0,0.25);
}
//layout
.input{
&::before{
content:'';
display:block;
position: absolute;
top:0;
left:0;
width: 100%;
height: 300px;
background: $dark-primary-color;
}
&-header{
position: relative;
padding-top:80px;
color: #fff;
h1{
padding-bottom:25px;
font-size:3.25em;
font-weight:100;
}
}
&-content{
position: relative;
padding:44px 55px;
background: #fff;
z-index:10;
h2{
padding-bottom:45px;
font-size:1.625em;
font-weight:bold;
vertical-align: middle;
span{
display: inline-block;
margin-left:10px;
padding:5px 6px 3px;
border:1px solid $sub-yellow;
border-radius:4px;
font-size:0.85rem;
vertical-align: middle;
color: $sub-yellow;
}
}
.inputbox{
overflow: hidden;
position: relative;
padding:15px 0 28px 200px;
&-title{
position: absolute;
top:15px;
left: 0;
width: 200px;
height: 30px;
color: #666;
font-weight: bold;
line-height: 30px;
}
&-content{
position: relative;
width: 100%;
input{
width: 100%;
height: 30px;
box-sizing: border-box;
line-height: 30px;
font-size:14px;
border:0;
background: none;
border-bottom:1px solid #ccc;
outline:none;
border-radius: 0;
-webkit-appearance: none;
&:focus,&:valid{
&~label{
color: $accent-color;
transform: translateY(-20px);
font-size:0.825em;
cursor:default;
}
}
&:focus{
&~.underline{
width: 100%;
}
}
}
label{
position: absolute;
top:0;
left:0;
height: 30px;
line-height: 30px;
color:#ccc;
cursor:text;
transition: all 200ms ease-out;
z-index:10;
}
.underline{
content:'';
display: block;
position: absolute;
bottom:-1px;
left:0;
width: 0;
height: 2px;
background: $accent-color;
transition: all 200ms ease-out;
}
}
}
.btns{
padding:30px 0 0 200px;
.btn{
display:inline-block;
margin-right:2px;
padding: 10px 25px;
background: none;
border:1px solid #c0c0c0;
border-radius:2px;
color: #666;
font-size:1.125em;
outline:none;
transition: all 100ms ease-out;
&:hover,&:focus{
transform: translateY(-3px);
}
&-confirm{
border:1px solid $accent-color;
background: $accent-color;
color: #fff;}
}
}
}
}
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.