Blogger Information
Blog 94
fans 0
comment 0
visits 92707
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
【CSS】伪类之:状态伪类介绍
可乐随笔
Original
321 people have browsed it

表单状态伪类

  1. /* 1. 匹配获取到焦点的元素*/
  2. fieldset :focus {
  3. background-color: lightgreen;
  4. transition: 0.5s;
  5. }
  6. /* 2. 匹配被选中的复选框元素*/
  7. input[type='checkbox']:checked + label {
  8. color: red;
  9. }
  10. /* 3. 当鼠标悬停到某个元素上的效果*/
  11. button {
  12. /* 去掉默认的边框与轮廓线 */
  13. border:none;
  14. outline:none;
  15. /*重置默认字体与背景色*/
  16. background-color: seagreen;
  17. color: white;
  18. padding: 5px 10px;
  19. /* 文字少,可适当拉开字间距 */
  20. letter-spacing: 1em;
  21. }
  22. /* 鼠标悬停按钮上的效果 */
  23. button:hover {
  24. cursor: pointer;
  25. opacity: 0.8;
  26. transition: 0.4s;
  27. }
  28. /* 4. checkbox实现下拉菜单的效果*/
  29. *原理*
  30. 1.将复选框的状态与下拉菜单列表进行绑定
  31. 2.根据复选框的状态决定下拉菜单是否显示
  32. */
  33. /* 初始状态:必须将复选框进行隐藏 */
  34. /* 隐藏复选框 */
  35. #menu {
  36. display: none;
  37. }
  38. /* 隐藏下拉菜单 */
  39. #menu + ul {
  40. display: none;
  41. }
  42. /* 状态伪类:显示下拉菜单 */
  43. #menu:checked + ul {
  44. display: block;
  45. }

示例HTML代码

  1. <form action="">
  2. <fieldset>
  3. <legend>用户注册</legend>
  4. <input type="text" id="username" name="username" placeholder="请输入用户名" autofocus required />
  5. <input type="password" id="password" name="password" placeholder="请输入密码" required />
  6. <input type="email" id="email" name="email" placeholder="请输入邮箱" required />
  7. <div><input type="checkbox" id="rem" name="remember" checked><label for="rem">记住我</label></div>
  8. <button>提交</button>
  9. </fieldset>
  10. </form>
  11. <div class="box">
  12. <!--label.for与input.id绑定-->
  13. <label for="menu">视频教程</label>
  14. <input type="checkbox" name="" id="menu">
  15. <ul>
  16. <li><a href="">前端开发</a></li>
  17. <li><a href="">后端开发</a></li>
  18. <li><a href="">全栈开发</a></li>
  19. </ul>
  20. </div>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post