Blogger Information
Blog 14
fans 0
comment 0
visits 7674
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
css基本、上下文、伪类、表单选择器
鹏建
Original
501 people have browsed it

简单选择器

选择器优先级

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>简单选择器</title>
  8. <style>
  9. /*元素选择器 */
  10. li{ color:blue;}
  11. /* 群组选择器 */
  12. h2,ul{font-size: 25px;}
  13. /* 通配选择器 */
  14. *{font-weight: bold;}
  15. /* 属性选择器 */
  16. *[title]{background-color: lightblue;}
  17. *[title=news]{font-style: italic;}
  18. /* 类选择器 */
  19. .radieo{background-color: #7cfc00;}
  20. /* id选择器 */
  21. #cartoon{background-color: lightcoral;}
  22. /* 标签选择器权重大于通配选择器 */
  23. li{font-weight: normal;}
  24. /* 类选择器权重大于标签选择器 */
  25. .radieo{color: orange;}
  26. /* id选择器权重大于类选择器 */
  27. #radieo{background-color:red;}
  28. </style>
  29. </head>
  30. <body>
  31. <h2>节目列表</h2>
  32. <ul>
  33. <li title="news" class="news">早间新闻</li>
  34. <li title="knowledge">知识大讲堂</li>
  35. <li>今日说法</li>
  36. <!-- /行内样式权重大于id选择器 -->
  37. <li id="cartoon" style="background-color: orangered;">动画片</li>
  38. <li>娱乐快递</li>
  39. <li class="radieo" id="radieo">电视剧</li>
  40. </ul>
  41. </body>
  42. </html>

上下文选择器

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>上下文选择器</title>
  8. <style>
  9. /* 后代选择器 */
  10. body *{ color:green;font-size: 25px;}
  11. /* 父子选择器 */
  12. ul>li{list-style-type: none;}
  13. /* 同级相邻选择器 */
  14. .news + .program{background-color: lawngreen;}
  15. /* 同级所有选择器 */
  16. .program.cartoon ~ .program{background-color: yellow;}
  17. </style>
  18. </head>
  19. <body>
  20. <h2 >节目列表</h2>
  21. <ul>
  22. <li class="news">早间新闻</li>
  23. <li class="program">知识大讲堂</li>
  24. <li class="program">今日说法</li>
  25. <li class="program cartoon">动画片</li>
  26. <li class="program">娱乐快递</li>
  27. <li class="program">电视剧</li>
  28. </ul>
  29. </body>
  30. </html>

伪类选择器不分组1

伪类选择器不分组2

伪类选择器不分组3

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>伪类选择器(不分组)</title>
  8. <style>
  9. tr:first-child{background-color: pink;}
  10. tr:last-child{background-color: yellow;}
  11. tr:nth-child(3){background-color: yellowgreen;}
  12. /* 前两个子元素 */
  13. tr:nth-child(-n+2){background-color: blue;}
  14. /* 后四个子元素 */
  15. tr:nth-last-child(-n+4){background-color: lightpink;}
  16. /* 奇数子元素 */
  17. tr:nth-child(2n+1){background-color:teal;}
  18. /* tr:nth-child(odd){background-color:teal;} */
  19. /* 偶数子元素 */
  20. tr:nth-child(2n){background-color:lightsalmon;}
  21. /* tr:nth-child(even){background-color:lightsalmon;} */
  22. </style>
  23. </head>
  24. <body>
  25. <table border="2" cellpadding="10" cellspacing="0" font-align="center">
  26. <caption style="font-size:30px;color:red;">基本信息</caption>
  27. <tr>
  28. <td>序号</td>
  29. <td>姓名</td>
  30. <td>性别</td>
  31. <td>年龄</td>
  32. </tr>
  33. <tr>
  34. <td>1</td>
  35. <td></td>
  36. <td></td>
  37. <td></td>
  38. </tr>
  39. <tr>
  40. <td>2</td>
  41. <td></td>
  42. <td></td>
  43. <td></td>
  44. </tr>
  45. <tr>
  46. <td>3</td>
  47. <td></td>
  48. <td></td>
  49. <td></td>
  50. </tr>
  51. <tr>
  52. <td>4</td>
  53. <td></td>
  54. <td></td>
  55. <td></td>
  56. </tr>
  57. <tr>
  58. <td>5</td>
  59. <td></td>
  60. <td></td>
  61. <td></td>
  62. </tr>
  63. </table>
  64. </body>
  65. </html>

伪类选择器分组1

伪类选择器分组2

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>伪类选择器(分组)</title>
  8. <style>
  9. div{padding: 20px;}
  10. table{text-align: center;margin: 20px;}
  11. .tbody1 tr:first-of-type{background-color: pink;}
  12. .tbody2 tr:last-of-type{background-color: yellow;}
  13. .tbody2 tr:nth-of-type(3){background-color: yellowgreen;}
  14. /* 前两个子元素 */
  15. .tbody2 tr:nth-of-type(-n+2){background-color: lightblue;}
  16. /* 后四个子元素 */
  17. .tbody1 tr:nth-last-type(-n+2){background-color: lightgreen;}
  18. /* 奇数子元素 */
  19. .tbody1 tr:nth-of-type(2n+1){background-color:lightgreen;}
  20. /*tbody1 tr:nth-of-type(odd){background-color:teal;} */
  21. /* 偶数子元素 */
  22. .tbody2 tr:nth-of-type(2n){background-color:lightsalmon;}
  23. /* tbody2 tr:nth-child(even){background-color:lightsalmon;} */
  24. </style>
  25. </head>
  26. <body>
  27. <div>
  28. <table border="2" cellpadding="10" cellspacing="0" >
  29. <caption style="font-size:30px;color:red;">基本信息</caption>
  30. <thead>
  31. <th>序号</th>
  32. <th>姓名</th>
  33. <th>性别</th>
  34. <th>年龄</th>
  35. </thead>
  36. <tbody class="tbody1">
  37. <tr>
  38. <td>1</td>
  39. <td></td>
  40. <td></td>
  41. <td></td>
  42. </tr>
  43. <tr>
  44. <td>2</td>
  45. <td></td>
  46. <td></td>
  47. <td></td>
  48. </tr>
  49. <tr>
  50. <td>3</td>
  51. <td></td>
  52. <td></td>
  53. <td></td>
  54. </tr>
  55. </tbody>
  56. <tbody class="tbody2">
  57. <tr>
  58. <td>1</td>
  59. <td></td>
  60. <td></td>
  61. <td></td>
  62. </tr>
  63. <tr>
  64. <td>2</td>
  65. <td></td>
  66. <td></td>
  67. <td></td>
  68. </tr>
  69. <tr>
  70. <td>3</td>
  71. <td></td>
  72. <td></td>
  73. <td></td>
  74. </tr>
  75. <tr>
  76. <td>4</td>
  77. <td></td>
  78. <td></td>
  79. <td></td>
  80. </tr>
  81. </tbody>
  82. </table>
  83. </body>
  84. </div>
  85. </html>

  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <style>
  10. .username:active{font-size:larger;}
  11. #password:focus{background-color:lightpink;}
  12. .password:hover{color: red;}
  13. a:link{color: blue;}
  14. a:visited{color:green}
  15. input:not(class){color:darkorange;}
  16. </style>
  17. <body>
  18. <a href="http://baidu.com/" target="blank">百度</a>
  19. <a href="https://www.php.cn/">php中文网</a>
  20. <form action="" method="get">
  21. <h2 >用户注册</h2>
  22. <section>
  23. <label for="username" class="username">用户名:</label>
  24. <input type="text" name="username" id="username" placeholder="手机/邮箱/账号" maxlength="18" size="20" autofocus/>
  25. </section>
  26. <section></section>
  27. <label for="password" class="password">密码:</label>
  28. <input type="password" id="password" name="password" placeholder="由字母、数字和下划线组成" maxlength="16" size="20"/ required>
  29. </section>
  30. <br>
  31. <input type="submit" value="提交" />
  32. </form>
  33. </body>
  34. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:unqualified

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