0

0

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

云罗郡主

云罗郡主

发布时间:2018-11-27 15:36:21

|

3396人浏览过

|

来源于css88

转载

本篇文章给大家带来的内容是关于如何利用css3实现input 输入框动画样式库,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

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

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

html代码:

Click every input.

EasySub – AI字幕生成翻译工具
EasySub – AI字幕生成翻译工具

EasySub 是一款在线 AI 字幕生成器。 它提供AI语音识别、AI字幕生成、AI字幕翻译,本来就很简单的视频剪辑。

下载

立即学习前端免费学习笔记(深入)”;

css代码:

@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-weight: 300;
 color: #fff;
 background: #efefef;
}
@mixin epic-sides() { // https://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;
   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;
     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;
 }
 
 + 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 .4s ease-in-out;
   border-top-left-radius: 3px;
   border-bottom-left-radius: 3px;
   transform-origin: left bottom;
   z-index: 99;
   
   &:before,
   &:after {
     content: "";
     position: absolute;
     top: 0;
     right: 0;
     bottom: 0;
     left: 0;
     border-radius: 3px;
     background: #377D6A;
     transform-origin: left bottom;
     transition: all .4s ease-in-out;
     pointer-events: none;
     z-index: -1;
   }
   &:before {
     background: rgba(3,36,41,.2);
     z-index: -2;
     right: 20%;
   }
 }
}
span:nth-child(2) .gate {
 text-indent: 85px;
}
span:nth-child(2) .gate:focus,
span:nth-child(2) .gate:active{
 text-indent: 0;
}
.gate:focus,
.gate:active {
 color: #377D6A;
 text-indent: 0;
 background: #fff;
 border-top-right-radius: 3px;
 border-bottom-right-radius: 3px;
 
 &::-webkit-input-placeholder {
   color: #aaa;
 }
 + label {
   transform: rotate(-66deg);
   border-radius: 3px;
   
   &:before {
     transform: rotate(10deg);
   }
 }
}
.skinny {
 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: 75px; // 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;
   padding: 10px 15px;
   text-shadow: 0 1px 0 rgba(19,74,70,.4);
   transition: all .3s ease-in-out;
   border-top-left-radius: 3px;
   border-bottom-left-radius: 3px;
   overflow: hidden;
 
   &:before,
   &:after {
     content: "";
     position: absolute;
     right: 0;
     left: 0;
     z-index: -1;
     transition: all .3s ease-in-out;
   }
   &:before {
     // Skinny bit here
     top: 5px;
     bottom: 5px;
     background: #377D6A; // change this to #134A46
     border-top-left-radius: 3px;
     border-bottom-left-radius: 3px;
   }
   &:after {
     top: 0;
     bottom: 0;
     background: #377D6A;
   }
 }
}
.skinny:focus,
.skinny:active {
 color: #377D6A;
 text-indent: 0;
 background: #fff;
 
 &::-webkit-input-placeholder {
   color: #aaa;
 }
 + label {
   transform: translateX(-100%);
   
   &:after {
     transform: translateX(100%);
   }
 }
}
.slide-up {
 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: 80px; // 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;
   padding: 10px 15px;
   text-shadow: 0 1px 0 rgba(19,74,70,.4);
   transition: all .3s ease-in-out;
   border-top-left-radius: 3px;
   border-bottom-left-radius: 3px;
   overflow: hidden;
 
   &:before,
   &:after {
     content: "";
     position: absolute;
     right: 0;
     left: 0;
     z-index: -1;
     transition: all .3s ease-in-out;
   }
   &:before {
     // Skinny bit here
     top: 6px;
     left: 5px;
     right: 5px;
     bottom: 6px;
     background: #377D6A; // change this to #134A46
   }
   &:after {
     top: 0;
     bottom: 0;
     background: #377D6A;
   }
 }
}
span:nth-child(1) .slide-up {
 text-indent: 105px;
}
span:nth-child(3) .slide-up {
 text-indent: 125px;
}
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-indent: 0;
}
.slide-up:focus,
.slide-up:active {
 color: #377D6A;
 text-indent: 0;
 background: #fff;
 
 &::-webkit-input-placeholder {
   color: #aaa;
 }
 + label {
   transform: translateY(-100%);
 
   &:before {
     border-radius: 5px;
   }
   &:after {
     transform: translateY(100%);
   }
 }
}
.card-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: 115px; // Arbitrary.
 transition: all .3s ease-in-out;
 
 &::-webkit-input-placeholder {
   color: #efefef;
   text-indent: 0;
   font-weight: 300;
 }
 
 + label {
   display: 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;
   transform-origin: right center;
   transform: perspective(300px) scaleX(1) rotateY(0deg);
 }
}
span:nth-child(2) .card-slide {
 text-indent: 55px;
}
span:nth-child(3) .card-slide {
 text-indent: 150px;
}
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-indent: 0;
}
.card-slide:focus,
.card-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: perspective(600px) translateX(-100%) rotateY(80deg);
 }
}
.swing {
 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;
   top: 0;
   left: 0;
   padding: 10px 15px;
   text-shadow: 0 1px 0 rgba(19,74,70,.4);
   background: #7AB893;
   border-top-left-radius: 3px;
   border-bottom-left-radius: 3px;
   transform-origin: 2px 2px;
   transform: rotate(0);
   // There should be a better way
   animation: swing-back .4s 1 ease-in-out;
 }
}
@keyframes swing {
 0% {
   transform: rotate(0);
 }
 20% {
   transform: rotate(116deg);
 }
 40% {
   transform: rotate(60deg);
 }
 60% {
   transform: rotate(98deg);
 }
 80% {
   transform: rotate(76deg);
 }
 100% {
   transform: rotate(82deg);
 }
}
@keyframes swing-back {
 0% {
   transform: rotate(82deg);
 }
 100% {
   transform: rotate(0);
 }
}
.swing:focus,
.swing:active {
 color: #377D6A;
 text-indent: 0;
 background: #fff;
 border-top-left-radius: 0;
 border-bottom-left-radius: 0;
 
 &::-webkit-input-placeholder {
   color: #aaa;
 }
 + label {
   animation: swing 1.4s 1 ease-in-out;
   transform: rotate(82deg);
 }
}
.balloon {
 // As suggested by https://twitter.com/dbox/status/365888496486985728
 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;
   top: 8px;
   left: 0;
   bottom: 8px;
   padding: 5px 15px;
   color: #032429;
   font-size: 11px;
   font-weight: 700;
   text-transform: uppercase;
   text-shadow: 0 1px 0 rgba(19,74,70,0);
   transition: all .3s ease-in-out;
   border-radius: 3px;
   background: rgba(122,184,147,0);
   
   &:after {
     position: absolute;
     content: "";
     width: 0;
     height: 0;
     top: 100%;
     left: 50%;
     margin-left: -3px;
     border-left: 3px solid transparent;
     border-right: 3px solid transparent;
     border-top: 3px solid rgba(122,184,147,0);
     transition: all .3s ease-in-out;
   }
 }
}
.balloon:focus,
.balloon:active {
 color: #377D6A;
 text-indent: 0;
 background: #fff;
 
 &::-webkit-input-placeholder {
   color: #aaa;
 }
 + label {
   color: #fff;
   text-shadow: 0 1px 0 rgba(19,74,70,.4);
   background: rgba(122,184,147,1);
   transform: translateY(-40px);
   
   &:after {
     border-top: 4px solid rgba(122,184,147,1);
   }
 }
}

以上就是对如何利用CSS3实现input 输入框动画样式库的全部介绍,如果您想了解更多有关CSS3教程,请关注PHP中文网。

相关专题

更多
高德地图升级方法汇总
高德地图升级方法汇总

本专题整合了高德地图升级相关教程,阅读专题下面的文章了解更多详细内容。

43

2026.01.16

全民K歌得高分教程大全
全民K歌得高分教程大全

本专题整合了全民K歌得高分技巧汇总,阅读专题下面的文章了解更多详细内容。

84

2026.01.16

C++ 单元测试与代码质量保障
C++ 单元测试与代码质量保障

本专题系统讲解 C++ 在单元测试与代码质量保障方面的实战方法,包括测试驱动开发理念、Google Test/Google Mock 的使用、测试用例设计、边界条件验证、持续集成中的自动化测试流程,以及常见代码质量问题的发现与修复。通过工程化示例,帮助开发者建立 可测试、可维护、高质量的 C++ 项目体系。

24

2026.01.16

java数据库连接教程大全
java数据库连接教程大全

本专题整合了java数据库连接相关教程,阅读专题下面的文章了解更多详细内容。

35

2026.01.15

Java音频处理教程汇总
Java音频处理教程汇总

本专题整合了java音频处理教程大全,阅读专题下面的文章了解更多详细内容。

16

2026.01.15

windows查看wifi密码教程大全
windows查看wifi密码教程大全

本专题整合了windows查看wifi密码教程大全,阅读专题下面的文章了解更多详细内容。

56

2026.01.15

浏览器缓存清理方法汇总
浏览器缓存清理方法汇总

本专题整合了浏览器缓存清理教程汇总,阅读专题下面的文章了解更多详细内容。

16

2026.01.15

ps图片相关教程汇总
ps图片相关教程汇总

本专题整合了ps图片设置相关教程合集,阅读专题下面的文章了解更多详细内容。

9

2026.01.15

ppt一键生成相关合集
ppt一键生成相关合集

本专题整合了ppt一键生成相关教程汇总,阅读专题下面的的文章了解更多详细内容。

26

2026.01.15

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3 教程
CSS3 教程

共18课时 | 4.6万人学习

HTML5/CSS3/JavaScript/ES6入门课程
HTML5/CSS3/JavaScript/ES6入门课程

共102课时 | 6.7万人学习

HTML+CSS基础与实战
HTML+CSS基础与实战

共132课时 | 9.6万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号