Blogger Information
Blog 11
fans 0
comment 0
visits 5792
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
css样式来源/选择器
becauses
Original
349 people have browsed it

css

样式来源

  • 默认样式
  • 行内样式 style=””
  • 文档样式 <style></style>
  • 外部样式 style.css

选择器

基本选择器

  • [属性]
  • # id
  • . class
  • * 通配符

    上下文选择器

  • > 子元素 只选择一代
  • 空格 所有后代
  • + 相邻兄弟
  • ~ 所有兄弟

css权重

  • 最高级:!important
  • 第一等:内链style=””
  • 第二等:ID选择器 #h3
  • 第三等:类选择器 .h3
  • 第四等:空格选择器 div h3
  • 通配符:子选择器、相邻选择器等

案例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 第三按文件和style顺序从下往上 -->
  9. <link rel="stylesheet" href="css.css">
  10. <style>
  11. *{
  12. font-size:45px;
  13. font-weight:bolder;
  14. }
  15. /* 子元素 只选择一代 */
  16. .div2>div>span{
  17. color:#159454;
  18. }
  19. /* 空格 所有后代 */
  20. .div3>div span{
  21. color:#8b9415;
  22. }
  23. /* 相邻兄弟 */
  24. .div4>div+ul{
  25. color:#849229;
  26. }
  27. /* 所有兄弟 ~ */
  28. .div5>div~ul{
  29. color:#359229;
  30. }
  31. /*
  32. 最高级:!important
  33. 第一等:内链style=""
  34. 第二等:ID选择器 #h3
  35. 第三等:类选择器 .h3
  36. 第四等:空格选择器 div h3
  37. 通配符:子选择器、相邻选择器等
  38. */
  39. div h3.h3#h3{
  40. color:#123456;
  41. }
  42. div h3.h3{
  43. color:#234567;
  44. }
  45. div h3{
  46. color:#345678;
  47. }
  48. h3{
  49. color:#456789;
  50. }
  51. /* 优先执行!important */
  52. .div{
  53. color:#4a498f !important;
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <div style="display: flex;" >
  59. <div style="width:50%;" >
  60. <!-- 第二执行style -->
  61. <div class="div" style="color:red;">123</div>
  62. <div class="div2" >
  63. <div>
  64. <span>11</span>
  65. </div>
  66. <div>
  67. <div>
  68. <span>22</span>
  69. </div>
  70. </div>
  71. </div>
  72. <div class="div3" >
  73. <div>
  74. <span>11</span>
  75. </div>
  76. <div>
  77. <div>
  78. <span>22</span>
  79. </div>
  80. </div>
  81. </div>
  82. <div class="div4" >
  83. <div>
  84. <span>11</span>
  85. </div>
  86. <ul>
  87. <li>222</li>
  88. </ul>
  89. <ul>
  90. <li>333</li>
  91. </ul>
  92. </div>
  93. <div class="div5" >
  94. <div>
  95. <span>11</span>
  96. </div>
  97. <ul>
  98. <li>222</li>
  99. </ul>
  100. <ul>
  101. <li>333</li>
  102. </ul>
  103. </div>
  104. </div>
  105. <div style="width:50%;" >
  106. <!-- 权重 -->
  107. <h3 class="h3" id="h3" >123</h3>
  108. </div>
  109. </div>
  110. </body>
  111. </html>
Correcting teacher:PHPzPHPz

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!