12种炫酷HTML5 SVG和CSS3表单浮动标签特效

36 篇文章 1 订阅
这是一组效果非常炫酷的SVG和CSS3表单浮动标签特效。这组浮动标签特效共12种效果,这些浮动标签效果部分在元素的伪元素上使用CSS transitions和CSS animations完成,一部分则使用SVG来制作变形动画。


在线演示

下载:201503191554.zip


        使用方法

        HTML结构


        这一组浮动标签特效最大的特点就是引入了SVG,使用SVG来制作各种图形变形动画,其中“SHOKO”的效果如下图所示:


        这个效果的HTML结构如下:
  1. <span class="input input--shoko">
  2.   <input class="input__field input__field--shoko" type="text" id="input-4" />
  3.   <label class="input__label input__label--shoko" for="input-4">
  4.     <span class="input__label-content input__label-content--shoko">Player Name</span>
  5.   </label>
  6.   <svg class="graphic graphic--shoko" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none">
  7.     <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"/>
  8.     <path d="M0,2.5c0,0,298.666,0,399.333,0C448.336,2.5,513.994,13,597,13c77.327,0,135-10.5,200.999-10.5c95.996,0,402.001,0,402.001,0"/>
  9.   </svg>
  10. </span>   
复制代码

        可以看到,两条线是使用SVG的<path>元素来制作的,后面将使用CSS来对它们进行变形动画。

        CSS样式

        在样式设计上,首先给标签文本和input输入框及SVG线条一些基本的样式:

  1. .input--shoko {
  2.   overflow: hidden;
  3.   padding-bottom: 2.5em;
  4. }

  5. .input__field--shoko {
  6.   padding: 0;
  7.   margin-top: 1.2em;
  8.   width: 100%;
  9.   background: transparent;
  10.   color: #fff;
  11.   font-size: 1.55em;
  12. }

  13. .input__label--shoko {
  14.   position: absolute;
  15.   top: 2em;
  16.   left: 0;
  17.   display: block;
  18.   width: 100%;
  19.   text-align: left;
  20.   padding: 0em;
  21.   text-transform: uppercase;
  22.   letter-spacing: 1px;
  23.   color: #A09C9C;
  24.   pointer-events: none;
  25.   -webkit-transform-origin: 0 0;
  26.   transform-origin: 0 0;
  27.   -webkit-transition: -webkit-transform 0.2s 0.1s, color 0.3s;
  28.   transition: transform 0.2s 0.1s, color 0.3s;
  29.   -webkit-transition-timing-function: ease-out;
  30.   transition-timing-function: ease-out;
  31. }

  32. .graphic--shoko {
  33.   stroke: #A09C9C;
  34.   pointer-events: none;
  35.   stroke-width: 2px;
  36.   top: 1.25em;
  37.   bottom: 0px;
  38.   height: 3.275em;
  39.   -webkit-transition: -webkit-transform 0.7s, stroke 0.7s;
  40.   transition: transform 0.7s, stroke 0.7s;
  41.   -webkit-transition-timing-function: cubic-bezier(0, 0.25, 0.5, 1);
  42.   transition-timing-function: cubic-bezier(0, 0.25, 0.5, 1);
  43. }            
复制代码

        当input输入框聚焦的时候,使用“+”选择器来选择相邻的文本,并使用transform来对它们进行动画。

  1. .input__field--shoko:focus + .input__label--shoko,
  2. .input--filled .input__label--shoko {
  3.   color: #A58282;
  4.   -webkit-transform: translate3d(0, 3.5em, 0) scale3d(0.85, 0.85, 1);
  5.   transform: translate3d(0, 3.5em, 0) scale3d(0.85, 0.85, 1);
  6. }      
复制代码

       同时,使用“~”选择器来选择SVG线条,并使它们产生波浪效果。

  1. .input__field--shoko:focus ~ .graphic--shoko,
  2. .input--filled .graphic--shoko {
  3.   stroke: #A58282;
  4.   -webkit-transform: translate3d(-66.6%, 0, 0);
  5.   transform: translate3d(-66.6%, 0, 0);
  6. }   
复制代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值