纯CSS3实现漂亮的input输⼊框
分享⼀个⽤纯 CSS3 实现的,漂亮的 input 输⼊框动画样式库-Text input love。
点击每个输⼊框都⽤不同的动画效果,始终显⽰标签label,并显⽰ placeholder(占位符)⽂本。
演⽰地址:
HTML 代码:
<div class="row">
<p>Click every input.</p>
</div>
<div class="row">
<span>
<input class="basic-slide" id="name" type="text" placeholder="Your best name" /><label for="name">Name</label>
</span>
<span>
<input class="basic-slide" id="email" type="text" placeholder="Your favorite email" /><label for="email">Email</label>
</span>
<span>
<input class="basic-slide" id="phone" type="text" placeholder="You can trust us" /><label for="phone">Phone</label>
</span>
</div>
<div class="row">
<span>
<input class="clean-slide" id="age" type="text" placeholder="Go for the high score!" /><label for="age">Age</label>
</span>
<span>
<input class="clean-slide" id="height" type="text" placeholder="Heels count" /><label for="height">Height</label>
</span>
<span>
<input class="clean-slide" id="weight" type="text" placeholder="Go ahead and lie" /><label for="weight">Weight</label> </span>
</div>
<div class="row">
<span>
<input class="gate" id="class" type="text" placeholder="Wizard!" /><label for="class">Class</label>
</span>
<span>
<input class="gate" id="element" type="text" placeholder="Five to choose from" /><label for="element">Element</label> </span>
<span>
<input class="gate" id="move" type="text" placeholder="Secret book attack!" /><label for="move">Move</label>
</span>
</div>
<div class="row">
<span>
<input class="skinny" id="english" type="text" placeholder="Do you speak it?" /><label for="english">English</label>
</span>
<span>
<input class="skinny" id="burger" type="text" placeholder="A Royale with cheese?" /><label for="bur
ger">Burger</label> </span>
</span>
<span>
<input class="skinny" id="wallet" type="text" placeholder="Bad Mother****er" /><label for="wallet">Wallet</label>
</span>
</div>
<div class="row">
<span>
<input class="slide-up" id="card" type="text" placeholder="Fund me!" /><label for="card">Credit Card</label>
</span>
<span>
<input class="slide-up" id="expires" type="text" placeholder="Month Day, Year" /><label for="expires">Expires</label> </span>
<span>
<input class="slide-up" id="security" type="text" placeholder="Public" /><label for="security">Security Code</label>
</span>
</div>
<div class="row">
<span>
<input class="card-slide" id="knock" type="text" placeholder="Who's there?" /><label for="knock">Knock knock</label> </span>
<span>
<input class="card-slide" id="max" type="text" placeholder="Max who?" /><label for="max">Max</label>
</span>
<span>
<input class="card-slide" id="out" type="text" placeholder="" /><label for="out">Maxed out card ;)</label>
</span>
</div>
<div class="row">
<span>
<input class="swing" id="artist" type="text" placeholder="BO$$" /><label for="artist">Artist</label>
</span>
<span>
<input class="swing" id="song" type="text" placeholder="I don't give a ****" /><label for="song">Song</label>
</span>
<span>
<input class="swing" id="eyes" type="text" placeholder="Crazy" /><label for="eyes">Eyes</label>
</span>
</div>
<div class="row">
<span>
<input class="balloon" id="state" type="text" placeholder="Liquid, solid, " /><label for="state">State</label> </span>
<span>
<input class="balloon" id="planet" type="text" placeholder="Probably Earth" /><label for="planet">Planet</label>
</span>
<span>
<input class="balloon" id="galaxy" type="text" placeholder="Milky Way?" /><label for="galaxy">Galaxy</label>
</span>
</div>
CSS 代码:
@import "compass/css3";
@import url(leapis/css?family=Open+Sans:400,700,600,300,800);
* {
box-sizing: border-box;
}
html,
body {
overflow-x: hidden;
font-family: "Open Sans", sans-serif;
font-weight: 300;
color: #fff;
background: #efefef;
background: #efefef;
}
@mixin epic-sides() { // codepen.io/MichaelArestad/pen/qltuk position: relative;
z-index: 1;
&:before {
position: absolute;
content: "";
display: block;
top: 0;
left: -5000px;
height: 100%;
width: 15000px;
z-index: -1;
@content;
}
}
.row {
max-width: 800px;
margin: 0 auto;
padding: 60px 30px;
background: #032429;
@include epic-sides() {background: inherit;}
text-align: center;
&:first-child {
padding: 40px 30px;
}
&:nth-child(2),
&:nth-child(8),
&:nth-child(10){
background: #134A46;
}
&:nth-child(3),
&:nth-child(7) {
background: #377D6A;
}
&:nth-child(4),
&:nth-child(6) {
background: #7AB893;
}
&:nth-child(5) {
background: #B2E3AF;
}
span {
position: relative;
display: inline-block;
margin: 30px 10px;
}
}
.basic-slide {
display: inline-block;
width: 215px;
padding: 10px 0 10px 15px;
font-family: "Open Sans", sans;
font-weight: 400;
color: #377D6A;
background: #efefef;
border: 0;
border-radius: 3px;
outline: 0;
text-indent: 70px; // Arbitrary.
transition: all .3s ease-in-out;
&::-webkit-input-placeholder {
color: #efefef;
text-indent: 0;
font-weight: 300;
}
+ label {
display: inline-block;
position: absolute;
top: 0;
left: 0;
padding: 10px 15px;
text-shadow: 0 1px 0 rgba(19,74,70,.4); background: #7AB893;
transition: all .3s ease-in-out;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
}
.basic-slide:focus,
.basic-slide:active {
color: #377D6A;
text-indent: 0;
background: #fff;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
&::-webkit-input-placeholder {
color: #aaa;
}
+ label {
transform: translateX(-100%);
}
}
.clean-slide {
position: relative;
display: inline-block;
width: 215px;
padding: 10px 0 10px 15px;
font-family: "Open Sans", sans;
font-weight: 400;
color: #377D6A;
background: #efefef;
border: 0;
border-radius: 3px;
outline: 0;
text-indent: 60px; // Arbitrary.
transition: all .3s ease-in-out;
&::-webkit-input-placeholder {
color: #efefef;
text-indent: 0;
font-weight: 300;
}
+ label {
display: inline-block;
position: absolute;
transform: translateX(0);
top: 0;
left: 0;
bottom: 0;
padding: 13px 15px;
font-size: 11px;
font-weight: 700;
font-weight: 700;
text-transform: uppercase;
color: #032429;
text-align: left;
text-shadow: 0 1px 0 rgba(255,255,255,.4);
transition: all .3s ease-in-out, color .3s ease-out; border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
overflow: hidden;
&:after {
content: "";
position: absolute;
top: 0;
好看的css代码right: 100%;
bottom: 0;
width: 100%;
background: #7AB893;
z-index: -1;
transform: translate(0);
transition: all .3s ease-in-out;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
}
}
.clean-slide:focus,
.clean-slide:active {
color: #377D6A;
text-indent: 0;
background: #fff;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
&::-webkit-input-placeholder {
color: #aaa;
}
+ label {
color: #fff;
text-shadow: 0 1px 0 rgba(19,74,70,.4);
transform: translateX(-100%);
&:after {
transform: translate(100%);
}
}
}
.
gate {
display: inline-block;
width: 215px;
padding: 10px 0 10px 15px;
font-family: "Open Sans", sans;
font-weight: 400;
color: #377D6A;
background: #efefef;
border: 0;
border-radius: 3px;
outline: 0;
text-indent: 65px; // Arbitrary.
transition: all .3s ease-in-out;
&::-webkit-input-placeholder {
color: #efefef;
text-indent: 0;
font-weight: 300;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论