温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

纯CSS3如何实现input输入框动画样式库

发布时间:2021-06-03 11:35:21 阅读:293 作者:小新 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

小编给大家分享一下纯CSS3如何实现input输入框动画样式库,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

分享一个用纯 CSS3 实现的,漂亮的 input 输入框动画样式库-Text input love。

点击每个输入框都用不同的动画效果,始终显示标签label,并显示 placeholder(占位符)文本。

纯CSS3如何实现input输入框动画样式库

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="burger">Burger</label>
  </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="Sunuva..." /><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, gaseous..." /><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>

SCSS 代码:

Sass 代码:

@import "compass/css3";
 
@import url(https://fonts.googleapis.com/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-weight300;
  color#fff;
  background#efefef;
}
@mixin epic-sides() { // https://codepen.io/MichaelArestad/pen/qltuk
    position: relative;
    z-index1;
 
    &:before {
        position: absolute;
        content"";
        display: block;
        top0;
        left: -5000px;
        height100%;
        width15000px;
        z-index: -1;
        @content;
    }
}
.row {
  max-width800px;
  margin0 auto;
  padding60px 30px;
  background#032429;
  @include epic-sides() {background: inherit;}
  text-align: center;
  
  &:first-child {
    padding40px 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;
    margin30px 10px;
  }
}
.basic-slide {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent70px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    background#7AB893;
    transition: all .3s ease-in-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
  }
}
.basic-slide:focus,
.basic-slide:active {
  color#377D6A;
  text-indent0;
  background#fff;
  border-top-left-radius0;
  border-bottom-left-radius0;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    transformtranslateX(-100%);
  }
}
.clean-slide {
  position: relative;
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent60px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    transformtranslateX(0);
    top0;
    left0;
    bottom0;
    padding13px 15px;
    font-size11px;
    font-weight700;
    text-transform: uppercase;
    color#032429;
    text-align: left;
    text-shadow0 1px 0 rgba(255,255,255,.4);
    transition: all .3s ease-in-out, color .3s ease-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    overflow: hidden;
    
    &:after {
      content"";
      position: absolute;
      top0;
      right100%;
      bottom0;
      width100%;
      background#7AB893;
      z-index: -1;
      transformtranslate(0);
      transition: all .3s ease-in-out;
      border-top-left-radius3px;
      border-bottom-left-radius3px;
    }
  }
}
.clean-slide:focus,
.clean-slide:active {
  color#377D6A;
  text-indent0;
  background#fff;
  border-top-left-radius0;
  border-bottom-left-radius0;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    color#fff;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    transformtranslateX(-100%);
    
    &:after {
      transformtranslate(100%);
    }
  }
}
.gate {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent65px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    background#7AB893;
    transition: all .4s ease-in-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    transform-origin: left bottom;
    z-index99;
    
    &:before,
    &:after {
      content"";
      position: absolute;
      top0;
      right0;
      bottom0;
      left0;
      border-radius3px;
      background#377D6A;
      transform-origin: left bottom;
      transition: all .4s ease-in-out;
      pointer-events: none;
      z-index: -1;
    }
    &:before {
      backgroundrgba(3,36,41,.2);
      z-index: -2;
      right20%;
    }
  }
}
span:nth-child(2.gate {
  text-indent85px;
}
span:nth-child(2.gate:focus,
span:nth-child(2.gate:active{
  text-indent0;
}
.gate:focus,
.gate:active {
  color#377D6A;
  text-indent0;
  background#fff;
  border-top-right-radius3px;
  border-bottom-right-radius3px;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    transformrotate(-66deg);
    border-radius3px;
    
    &:before {
      transformrotate(10deg);
    }
  }
}
.skinny {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent75px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    transformtranslateX(0);
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    transition: all .3s ease-in-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    overflow: hidden;
 
    &:before,
    &:after {
      content"";
      position: absolute;
      right0;
      left0;
      z-index: -1;
      transition: all .3s ease-in-out;
    }
    &:before {
      // Skinny bit here
      top5px;
      bottom5px;
      background#377D6A; // change this to #134A46
      border-top-left-radius3px;
      border-bottom-left-radius3px;
    }
    &:after {
      top0;
      bottom0;
      background#377D6A;
    }
  }
}
.skinny:focus,
.skinny:active {
  color#377D6A;
  text-indent0;
  background#fff;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    transformtranslateX(-100%);
    
    &:after {
      transformtranslateX(100%);
    }
  }
}
.slide-up {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent80px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    transformtranslateX(0);
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    transition: all .3s ease-in-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    overflow: hidden;
 
    &:before,
    &:after {
      content"";
      position: absolute;
      right0;
      left0;
      z-index: -1;
      transition: all .3s ease-in-out;
    }
    &:before {
      // Skinny bit here
      top6px;
      left5px;
      right5px;
      bottom6px;
      background#377D6A; // change this to #134A46
    }
    &:after {
      top0;
      bottom0;
      background#377D6A;
    }
  }
}
span:nth-child(1.slide-up {
  text-indent105px;
}
span:nth-child(3.slide-up {
  text-indent125px;
}
span:nth-child(1.slide-up:focus,
span:nth-child(1.slide-up:active,
span:nth-child(3.slide-up:focus,
span:nth-child(3.slide-up:active {
  text-indent0;
}
.slide-up:focus,
.slide-up:active {
  color#377D6A;
  text-indent0;
  background#fff;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    transformtranslateY(-100%);
 
    &:before {
      border-radius5px;
    }
    &:after {
      transformtranslateY(100%);
    }
  }
}
.card-slide {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent115px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: block;
    position: absolute;
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    background#7AB893;
    transition: all .3s ease-in-out;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    transform-origin: right center;
    transformperspective(300pxscaleX(1rotateY(0deg);
  }
}
span:nth-child(2.card-slide {
  text-indent55px;
}
span:nth-child(3.card-slide {
  text-indent150px;
}
span:nth-child(2.card-slide:focus,
span:nth-child(2.card-slide:active,
span:nth-child(3.card-slide:focus,
span:nth-child(3.card-slide:active {
  text-indent0;
}
.card-slide:focus,
.card-slide:active {
  color#377D6A;
  text-indent0;
  background#fff;
  border-top-left-radius0;
  border-bottom-left-radius0;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    transformperspective(600pxtranslateX(-100%rotateY(80deg);
  }
}
.swing {
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent60px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    top0;
    left0;
    padding10px 15px;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    background#7AB893;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
    transform-origin2px 2px;
    transformrotate(0);
    // There should be a better way
    animation: swing-back .4s 1 ease-in-out;
  }
}
@keyframes swing {
  0% {
    transformrotate(0);
  }
  20% {
    transformrotate(116deg);
  }
  40% {
    transformrotate(60deg);
  }
  60% {
    transformrotate(98deg);
  }
  80% {
    transformrotate(76deg);
  }
  100% {
    transformrotate(82deg);
  }
}
@keyframes swing-back {
  0% {
    transformrotate(82deg);
  }
  100% {
    transformrotate(0);
  }
}
.swing:focus,
.swing:active {
  color#377D6A;
  text-indent0;
  background#fff;
  border-top-left-radius0;
  border-bottom-left-radius0;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    animation: swing 1.4s 1 ease-in-out;
    transformrotate(82deg);
  }
}
.balloon {
  // As suggested by https://twitter.com/dbox/status/365888496486985728
  display: inline-block;
  width215px;
  padding10px 0 10px 15px;
  font-family"Open Sans", sans;
  font-weight400;
  color#377D6A;
  background#efefef;
  border0;
  border-radius3px;
  outline0;
  text-indent60px; // Arbitrary.
  transition: all .3s ease-in-out;
  
  &::-webkit-input-placeholder {
    color#efefef;
    text-indent0;
    font-weight300;
  }
 
  + label {
    display: inline-block;
    position: absolute;
    top8px;
    left0;
    bottom8px;
    padding5px 15px;
    color#032429;
    font-size11px;
    font-weight700;
    text-transform: uppercase;
    text-shadow0 1px 0 rgba(19,74,70,0);
    transition: all .3s ease-in-out;
    border-radius3px;
    backgroundrgba(122,184,147,0);
    
    &:after {
      position: absolute;
      content"";
      width0;
      height0;
      top100%;
      left50%;
      margin-left: -3px;
      border-left3px solid transparent;
      border-right3px solid transparent;
      border-top3px solid rgba(122,184,147,0);
      transition: all .3s ease-in-out;
    }
  }
}
.balloon:focus,
.balloon:active {
  color#377D6A;
  text-indent0;
  background#fff;
  
  &::-webkit-input-placeholder {
    color#aaa;
  }
  + label {
    color#fff;
    text-shadow0 1px 0 rgba(19,74,70,.4);
    backgroundrgba(122,184,147,1);
    transformtranslateY(-40px);
    
    &:after {
      border-top4px solid rgba(122,184,147,1);
    }
  }
}

看完了这篇文章,相信你对“纯CSS3如何实现input输入框动画样式库”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://www.jb51.net/css/652967.html

AI

开发者交流群×