首页 技术 正文
技术 2022年11月20日
0 收藏 352 点赞 4,812 浏览 4702 个字

用css3和jQuery制作一个简单的精美表单

html代码如下:

<span class=”title”>Mask Your Input Forms and Make It Beauty</span> <br/><br/> <div id=”container”> <p class=”separator”><br/></p> <p class=”small-title”>Too Plain</p> <input class=”too-plain” value=”Enter your email here” /> <p class=”separator”><br/></p> <p class=”small-title”>Fading The Label</p> <form>     <label class=”username-label” for=”username”>Username</label>     <input type=”text” name=”username” class=”username” />     <label class=”password-label” for=”password”>Password</label>     <input type=”password” name=”password” class=”password” /> </form> <p class=”separator”><br/></p> <p class=”small-title”>Sliding? Don’t Worry</p> <form>     <label class=”username-label-sliding” for=”username-sliding”>Username</label>     <input type=”text” name=”username” class=”username-sliding” />     <label class=”password-label-sliding” for=”password-sliding”>Password</label>     <input type=”password” name=”password” class=”password-sliding” /> </form> <p class=”separator”><br/></p> </div>

css代码如下:

* {     margin:0;     padding:0; } body {     text-align:center;     font-family:Georgia, “Times New Roman”, Times, serif;     font-size:13px;     line-height:1.5em;     margin-top:8%;     background:#eaeaea; } input {     padding:7px;     border:5px solid #e0e0e0;     -webkit-border-radius:20px;     border-radius:20px;     -moz-border-radius:20px; } input:focus {     outline:none; } #container {     text-align:left;     width:700px;     margin-left:auto;     margin-right:auto; } .separator {     border-bottom:1px dashed #ccc;     margin-bottom:3px; } .title {     font-size:30px;     margin-bottom:1.5em;     font-weight:bold;     font-style:italic;     text-shadow:0 2px 0 #fff; } .small-title {     font-size:20px;     margin-bottom:0.5em;     font-weight:bold;     font-style:italic;     text-shadow:0 2px 0 #fff; } .username-label, .password-label, .username-label-sliding, .password-label-sliding {     position:absolute;     margin:9px 9px 9px 12px; } .username-sliding, .password-sliding {     width:150px; } a, a:visited, a:hover {     text-decoration: none;     color: #000; }

jQuery代码如下:

$(document).ready(function(){       $(‘.too-plain’).focus(function(){           if($(this).val()==”Enter your email here”)           {$(this).val(“”);}                      }).blur(function(){                              if($(this).val()==””)               {                   $(this).val(‘Enter your email here’);                   }               });               $(“.username-label,.password-label”).animate({ opacity: “0.4” }).click(function(){                   var thisFor=$(this).attr(“for”);                   $(‘.’+thisFor).focus();                   })                   $(“.username”).focus(function(){                       $(“.username-label”).animate({opacity:”0″},”fast”);                       if($(this).val()==”username”)                       {                           $(this).val()==””;                           }                                              }).blur(function(){                           if($(this).val()==””)                           {                               $(this).val()==”username”;                               $(“.username-label”).animate({opacity:”0.4″},”fast”);                               }                           })             $(‘.password’).focus(function(){                                  $(“.password-label”).animate({opacity:”0″},”fast”);                 if($(this).val()==”password”){                     $(this).val()==””;                     }                                  }).blur(function(){                     if($(this).val()==””)                     {                         $(this).val()==”password”;                         $(‘.password-label’).animate({opacity:”0.4″},”fast”);                          }                                          });                     $(‘.username-label-sliding,.password-label-sliding’).animate({opacity:”0.4″}).click(function(){                         var thisFor=$(this).attr(‘for’)                             $(‘.’+thisFor).focus();                         })                             $(‘.username-sliding’).focus(function() {                                      $(‘.username-label-sliding’).animate({ marginLeft: “7em” }, “fast”);                                          if($(this).val() == “username”)                             $(this).val() == “”;                              }).blur(function() {                                          if($(this).val() == “”) {                             $(this).val() == “username”;                             $(‘.username-label-sliding’).animate({ marginLeft: “12px” }, “fast”);                         }                     });                              $(‘.password-sliding’).focus(function() {                                      $(‘.password-label-sliding’).animate({ marginLeft: “7em” }, “fast”);                                          if($(this).val() == “password”) {                             $(this).val() == “”;                         }                     }).blur(function() {                                          if($(this).val() == “”) {                             $(this).val() == “password”;                             $(‘.password-label-sliding’).animate({ marginLeft: “12px” }, “fast”);                         }                 });       })

在firefox3.6,ie9,chrome中预览效果下图:

用css3和jQuery制作精美的表单

在ie7/8中预览效果如下图:

用css3和jQuery制作精美的表单

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,967
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,487
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,332
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,115
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,748
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,783