表单/表格

浮动标签提交表单用户界面设计

阿里云


这是一款非常简洁的浮动标签提交表单用户界面设计效果。这个浮动标签效果包括输入框浮动标签,下拉列表浮动标签和文本域浮动标签。该浮动标签表单简洁大方,是设计表单不错的选择。

HTML 结构

以文本框的浮动标签效果为例,它的 HTML 结构如下:使用一个 div 作为包裹元素,里面放置一个 input 元素和一个 label 标签,它们通过 label 元素的 for 属性进行关联。

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

CSS 样式

特效中首先对输入框进行了一些美化工作。

  1. .controls {
  2.   text-align: left;
  3.   position: relative;
  4. }
  5. .controls input[type="text"],
  6. .controls input[type="email"],
  7. .controls input[type="tel"],
  8. .controls textarea,
  9. .controls button,
  10. .controls select {
  11.   padding: 12px;
  12.   font-size: 14px;
  13.   border: 1px solid #c6c6c6;
  14.   width: 100%;
  15.   margin-bottom: 18px;
  16.   color: #888;
  17.   font-family: 'Lato', 'sans-serif';
  18.   font-size: 16px;
  19.   font-weight: 300;
  20.   background-color: #fff;
  21.   -moz-border-radius: 2px;
  22.   -webkit-border-radius: 2px;
  23.   border-radius: 2px;
  24.   -moz-transition: all 0.3s;
  25.   -o-transition: all 0.3s;
  26.   -webkit-transition: all 0.3s;
  27.   transition: all 0.3s;
  28. }
  29. .controls input[type="text"]:focus, .controls input[type="text"]:hover,
  30. .controls input[type="email"]:focus,
  31. .controls input[type="email"]:hover,
  32. .controls input[type="tel"]:focus,
  33. .controls input[type="tel"]:hover,
  34. .controls textarea:focus,
  35. .controls textarea:hover,
  36. .controls button:focus,
  37. .controls button:hover,
  38. .controls select:focus,
  39. .controls select:hover {
  40.   outline: none;
  41.   border-color: #9FB1C1;
  42. }
  43. .controls input[type="text"]:focus + label, .controls input[type="text"]:hover + label,
  44. .controls input[type="email"]:focus + label,
  45. .controls input[type="email"]:hover + label,
  46. .controls input[type="tel"]:focus + label,
  47. .controls input[type="tel"]:hover + label,
  48. .controls textarea:focus + label,
  49. .controls textarea:hover + label,
  50. .controls button:focus + label,
  51. .controls button:hover + label,
  52. .controls select:focus + label,
  53. .controls select:hover + label {
  54.   color: #077ABC;
  55.   cursor: text;
  56. }

占位标签采用绝对定位,并对文字颜色和背景色设置了过渡动画效果。

  1. .controls label {
  2.   position: absolute;
  3.   left: 8px;
  4.   top: 12px;
  5.   color: #999;
  6.   font-size: 16px;
  7.   display: inline-block;
  8.   padding: 4px 10px;
  9.   font-weight: 400;
  10.   background-color: rgba(255, 255, 255, 0);
  11.   pointer-events: none;
  12.   -moz-transition: color 0.3s, top 0.3s, background-color 0.8s;
  13.   -o-transition: color 0.3s, top 0.3s, background-color 0.8s;
  14.   -webkit-transition: color 0.3s, top 0.3s, background-color 0.8s;
  15.   transition: color 0.3s, top 0.3s, background-color 0.8s;
  16. }

当输入框聚焦的时候,它被添加了.active class 类,该 class 通过修改 top 属性来移动标签。

  1. .controls label.active {
  2.   top: -11px;
  3.   color: #555;
  4.   background-color: white;
  5. }

JavaScript

该浮动标签表单使用 jQuery 代码来在输入框聚焦和失去焦点的时候为元素添加和移除 active class。

浮动标签提交表单用户界面设计

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

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

发表回复

热销模板

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

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