表单/表格

炫酷设计表单浮动标签jQuery效果

阿里云


这是一款使用 CSS3 制作的炫酷炫酷浮动标签设计效果。该浮动标签效果分为标签上浮动,标签右浮动和标签下浮动效果,它们均通过 CSS3 和少量 jQuery 代码来完成。

HTML 结构

所有的浮动标签均使用一个<div>作为容器,然后里面放置一个<input>元素和一个<label>元素。

也想出现在这里?联系我们
创客主机
  1. <div class="input-element">
  2.   <label for="input">Float top label</label>
  3.   <input type="text" id="input" name="input">
  4. </div>

CSS 样式

首先为<input>元素和<label>元素设置基本的 CSS 样式。

  1. .container {
  2.   width: 300px;
  3.   margin: 0 auto;
  4.   position: absolute;
  5.   top: 50%;
  6.   left: 50%;
  7.   -webkit-transform: translate(-50%, -51%);
  8.   transform: translate(-50%, -51%);
  9.   -webkit-backface-visibility: hidden;
  10. }
  11.  
  12. .input-element {
  13.   margin: 0 auto;
  14.   padding-top: 30px;
  15.   position: relative;
  16.   overflow: visible;
  17. }
  18. .input-element:last-child {
  19.   margin-bottom: 0;
  20. }
  21. .input-element:after {
  22.   content: " ";
  23.   display: block;
  24.   position: absolute;
  25.   bottom: 0;
  26.   left: 0;
  27.   width: 100%;
  28.   height: 1px;
  29.   background: #fff;
  30. }
  31. .input-element:before {
  32.   content: " ";
  33.   display: block;
  34.   position: absolute;
  35.   bottom: 0;
  36.   width: 0;
  37.   height: 1px;
  38.   background: #3B7FC4;
  39.   -webkit-transition: width .3s ease-in-out;
  40.   transition: width .3s ease-in-out;
  41.   z-index: 20;
  42.   left: 50%;
  43.   -webkit-transform: translateX(-50%);
  44.   transform: translateX(-50%);
  45. }
  46. .input-element.right:before {
  47.   left: 0;
  48.   -webkit-transform: translateX(0);
  49.   transform: translateX(0);
  50. }
  51. .input-element label {
  52.   -webkit-backface-visibility: hidden;
  53.   -moz-backface-visibility: hidden;
  54.   -ms-backface-visibility: hidden;
  55.   -webkit-transform: translateZ(0);
  56.   transform: translateZ(0);
  57.   color: #fff;
  58.   top: 42px;
  59.   left: 0;
  60.   position: absolute;
  61.   -webkit-transition: all 0.3s ease-in-out;
  62.   transition: all 0.3s ease-in-out;
  63.   width: 100%;
  64. }
  65. .input-element label:hover {
  66.   cursor: pointer;
  67.   color: #efefef;
  68. }
  69. .input-element input {
  70.   width: 100%;
  71.   padding: 8px 0;
  72.   background: none;
  73.   border: none;
  74.   outline: none;
  75.   color: #fff;
  76.   font-size: 18px;
  77.   -webkit-backface-visibility: hidden;
  78. }

在 input 元素聚焦的时候,通过 jQuery 来为它添加.active 的 class 类,此时修改 label 标签位置和字体大小。

  1. .input-element.active label {
  2.   top: 15px;
  3.   color: #3B7FC4;
  4.   font-size: 12px;
  5. }

如果想使标签右浮动,则添加一个.right 的 class 类即可,向下浮动添加.bottom class 类。

  1. .input-element.active.right label {
  2.   top: 42px;
  3.   left: 100%;
  4.   font-size: 18px;
  5. }
  6. .input-element.active.bottom label {
  7.   top: calc(100% + 5px);
  8.   font-size: 14px;
  9. }

炫酷设计表单浮动标签 jQuery 效果

已有 354 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!