今天来说说对input输入框在处理上的细节处理和心得,其实制作一个符合CSS标准、FF/IE7/IE6等主流浏览器全兼容、符合用户体验的input其实并不难。先点击看看下面的效果先!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>表单效果</title> <style type="text/css"> *{ margin:0; padding:0; } body{ font-size:63%; color:#000; } /*input*/ .input_on{ padding:2px 8px 0pt 3px; height:18px; border:1px solid #999; background-color:#FFFFCC; } .input_off{ padding:2px 8px 0pt 3px; height:18px; border:1px solid #CCC; background-color:#FFF; } .input_move{ padding:2px 8px 0pt 3px; height:18px; border:1px solid #999; background-color:#FFFFCC; } .input_out{ /*height:16px;默认高度*/ padding:2px 8px 0pt 3px; height:18px; border:1px solid #CCC; background-color:#FFF; } /*form*/ ul.input_test{ margin:20px auto 0 auto; width:500px; list-style-type:none; } ul.input_test li{ width:500px; height:22px; margin-bottom:10px; } .input_test label{ float:left; padding-right:10px; width:100px; line-height:22px; text-align:right; font-size:1.4em; } .input_test p{ float:left; _margin-top:-1px; } .input_test span{ float:left; padding-left:10px; line-height:22px; text-align:left; font-size:1.2em; color:#999; } </style> </head> <body> <ul class="input_test"> <li> <label for="inp_name">姓名:</label> <p><input id="inp_name" class="input_out" name="" type="text" onfocus="this.className='input_on';this.onmouseout=''" onblur="this.className='input_off';this.onmouseout=function(){this.className='input_out'};" onmousemove="this.className='input_move'" onmouseout="this.className='input_out'" /></p> <span>请输入您的姓名</span> </li> <li> <label for="inp_email">Email:</label> <p><input id="inp_email" class="input_out" name="" type="text" onfocus="this.className='input_on';this.onmouseout=''" onblur="this.className='input_off';this.onmouseout=function(){this.className='input_out'};" onmousemove="this.className='input_move'" onmouseout="this.className='input_out'" /></p> <span>请输入您的Email</span> </li> <li> <label for="inp_web">网站:</label> <p><input id="inp_web" class="input_out" name="" type="text" onfocus="this.className='input_on';this.onmouseout=''" onblur="this.className='input_off';this.onmouseout=function(){this.className='input_out'};" onmousemove="this.className='input_move'" onmouseout="this.className='input_out'" /></p> <span>请输入您的网站</span> </li> </ul> </body> </html>
鼠标经过input时的颜色会发生变化,此外当点击标题处(2e1cf0710519d5598b1f0f14c36ba674的作用)或者输入框时,光标停留所在的input的颜色也和其他input输入框有所不同,这是d5fd7aea971a85678ba271703566ebfd中JS的作用。在用户体验上告诉的用户什么是可以输入以及当前在什么输入位置。此外通过键盘上Tab键的切换,输入完当前内容移动到下一个输入框变得更方便了,这是CSS合理布局结构的作用。
整体的结构通过ff6d136ddc5fdfeffaf53ff6ee95f185和25edfb22a4f469ecb59f1190150159c6来组织,每个25edfb22a4f469ecb59f1190150159c6显示一行内容。2e1cf0710519d5598b1f0f14c36ba674标签显示标题,e388a4556c0f65e1904146cc1a846beeinput控制输入框,45a2772a6b6107b401db3c9b82c049c2显示备注信息。这里要特别说一下d5fd7aea971a85678ba271703566ebfd在各个浏览器下不同的表现,对d5fd7aea971a85678ba271703566ebfd设置line-height对FF是不起作用的,所以建议用padding来控制文本在输入框的位置。d5fd7aea971a85678ba271703566ebfd在浏览器下的默认高度和字体一样是16px,加上下边框就是18px。特别是在需要将d5fd7aea971a85678ba271703566ebfd变大的情况下,用padding来控制比较好。
再来说说JS部分,这里用到onblur(光标离开)、onfocus(光标停留)、onmousemove(鼠标停留)、onmouseout(鼠标离开)这4个属性来控制鼠标的动作。不会JS也没关系,只要定义其所对应的CSS样式就可以了。
以上是网站中比较不错的表单特效实例代码的详细内容。更多信息请关注PHP中文网其他相关文章!

您是否曾经在项目上需要一个倒计时计时器?对于这样的东西,可以自然访问插件,但实际上更多


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

Atom编辑器mac版下载
最流行的的开源编辑器

Dreamweaver CS6
视觉化网页开发工具

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。