2_CSS选择器.html 895 B

123456789101112131415161718192021222324252627282930313233343536
  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>Document</title>
  7. <style>
  8. /* 标签选择器 */
  9. /* 标签选择器 根据标签名获取html标签 */
  10. /* div{
  11. color: red;
  12. } */
  13. /* 类选择器 */
  14. /* 根据类名获取html标签 类名允许重复*/
  15. .box1{
  16. color: red;
  17. }
  18. .box2{
  19. color: blue;
  20. }
  21. /* ID选择器 */
  22. /* 根据ID获取html标签 ID不允许重复 */
  23. #div1{
  24. color: green;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="box1">hello world</div>
  30. <div class="box2">你好世界</div>
  31. <div class="box2" id="div1">love coding</div>
  32. <!-- ID不允许重复 -->
  33. <!-- <div id="div1">hello</div> -->
  34. </body>
  35. </html>