CSS3的伪类选择器就是多,今天我们来学习新的伪类选择器——UL状态伪类选择器。这些选择器都有一个共同的特征名那就是定义的样式只有当元素处于某种状态下时才起作用,在默认状态下无效。

今天我们先来接触:hover、active和:focus这三种状态伪类选择器。

:hover选择器、:active选择器和:focus选择器
:hover选择器:当鼠标悬停在所指定的元素上时所使用的样式;
:active选择器:当所指定的元素处于激活状态(鼠标在元素上按下还没有松开)时所使用的样式;
:focus选择器:当元素获得光标焦点时使用的样式,主要用在文本框输入文字时使用;
【注】下方案例运行效果,之所以点击后立即变为绿色是因为active触发的同时focus也触发了,所以active定义的样式看似无效,大家可以先把focus定义的样式注释掉运行;

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset=”gb2312″>
  5. <title>CSS3实例教程:hover、active和:focus伪选择器——网页教学网webjx.com</title>
  6. <style type=”text/css”>
  7. *{margin:0; padding:0;}
  8. body{margin-bottom:20px; font-family:”Microsoft yahei”; font-size:14px;}
  9. ul{margin:50px auto; width:260px; height:100px; list-style:none;}
  10. ul li{margin-bottom:10px; overflow:hidden;}
  11. label,input{display:inline; float:left;}
  12. label{padding-right:8px; width:50px; height:27px; line-height:27px; text-align:right;}
  13. input{width:200px; height:25px; border:1px #eee solid; border-top:1px #d1d1d1 solid; outline:none;}
  14. input:hover{background:#eff7ff;}
  15. input:active{background:#ffd;}
  16. input:focus{background:#f2fddb;}
  17. </style>
  18. </head>
  19. <body>
  20. <ul>
  21. <li>
  22. <label for=”userName”>姓名:</label>
  23. <input id=”userName” type=”text”/>
  24. </li>
  25. <li>
  26. <label for=”userPwd”>密码:</label>
  27. <input id=”userPwd” type=”password”/>
  28. </li>
  29. </ul>
  30. </body>
  31. </html>

【技术交流】用javascrifp和html写的简单的新用户注册界面

这只是一个页面,完成不了注册的功能。没有数据库,而且提交表单的时候没有链接的页。仅供参考。想演示的可以将下面的代码复制到记事本当中,随便起个名保存...

阅读全文

【网站建设】28个你必须知道的HTML5的新特性,技巧以及技术

                          1. 新的Doctype 尽管使用<!DOCTYPE html>,即使浏览...

阅读全文