Blogger Information
Blog 56
fans 1
comment 0
visits 62330
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
伪类与伪元素
零龙
Original
660 people have browsed it

伪类与伪元素


伪类

  • :target 必须ID配合,实现锚点操作。

  • :focus 当获取焦点的时候

  • ::selection 设置选中文本的前景色与背景色

  • :not() 用于选中不满足条件的元素

伪元素 (设定浏览器生成的元素)

  • ::before 对象前面生成的内容

  • ::after 对象后面生成的内容


实例:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>伪类和微元素</title>
  7. </head>
  8. <style>
  9. /* :target 必须配合ID实现锚点操作。 */
  10. #login-form
  11. {
  12. display:none;
  13. }
  14. #login-form:target
  15. {
  16. display: block;
  17. }
  18. input:focus
  19. {
  20. background-color: black;
  21. }
  22. input::selection
  23. {
  24. background-color: rgb(255, 0, 85);
  25. color: chartreuse;
  26. }
  27. .list > :not(:nth-of-type(3)) {
  28. color: red;
  29. }
  30. .list::before {
  31. content: "购物车";
  32. color: blue;
  33. font-size: 1.5rem;
  34. border-bottom: 1px solid #000;
  35. }
  36. .list::after {
  37. content: "结算中...";
  38. color: red;
  39. font-size: 1.1rem;
  40. }
  41. </style>
  42. <body>
  43. <a href="#login-form">登录</a>
  44. <form method="POST" id="login-form" action="">
  45. <label for="username">用户名:</label>
  46. <input type="text" name="username" id="username">
  47. <label for="password">密码:</label>
  48. <input type="password" name="password" id="password">
  49. <button>登录</button>
  50. </form>
  51. <ul class="list">
  52. <li>item1</li>
  53. <li>item2</li>
  54. <li>item3</li>
  55. <li>item4</li>
  56. </ul>
  57. </body>
  58. </html>

实例效果图

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:作业似乎没写完。。。
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