1.实例演示选择器的优先级,id,class,tag;

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>优先级</title>
  8. <style>
  9. /* 1,1,3 */
  10. html body h1#first.active {
  11. color: rgb(230, 17, 183);
  12. }
  13. /* id选择器,优先级大于class */
  14. /* 1,0,3 */
  15. html body h1#first {
  16. color: rgb(59, 17, 158);
  17. }
  18. /* 1,0,2 */
  19. body h1#first {
  20. color: blue;
  21. }
  22. /* 选择器本身优先级大于书写顺序 */
  23. /* 类样式 */
  24. /* 0,1,2 */
  25. html h1.active {
  26. color: seagreen;
  27. }
  28. /* 0,1,1 */
  29. h1.active {
  30. color: yellow;
  31. }
  32. /* 标签 * * 优先级相同时,书写顺序决定优先级 */
  33. /* 0, 0, 3 */
  34. html body h1 {
  35. color: rgb(10, 133, 10);
  36. }
  37. /* 0, 0, 3 */
  38. html body h1 {
  39. color: rgb(131, 39, 216);
  40. }
  41. </style>
  42. </head>
  43. <body>
  44. <h1 class="active" id="first">3月22日的练习</h1>
  45. <h2>id 大于 class 大于 tag,关键是要分清有多少个id,多少个class,多少个tag</h2>
  46. </body>
  47. </html>

2.实例演示前端组件样式模块化的原理与实现;

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>模块化样式表</title>
  8. <!-- 使用外部样式方式一 -->
  9. <link rel="stylesheet" href="css/index.css" />
  10. <!-- 使用外部样式方式二 -->
  11. <!-- <style>
  12. @import url(css/index.css);
  13. </style> -->
  14. </head>
  15. <body>
  16. <header>页眉</header>
  17. <main>主体</main>
  18. <footer>页脚</footer>
  19. </body>
  20. </html>
  21. <!--index.css文件-->
  22. @import url(header.css);
  23. @import url(main.css);
  24. @import url(footer.css);
  25. <!--heater.css文件-->
  26. header {
  27. min-height: 3em;
  28. background-color: rgb(143, 167, 245);
  29. }
  30. <!--main.css文件-->
  31. main {
  32. min-height: 20em;
  33. background-color: rgb(197, 231, 133);
  34. }
  35. <!--footer.css文件-->
  36. footer {
  37. min-height: 5em;
  38. background-color: rgb(144, 163, 226);
  39. }

3.实例演示常用伪类选择器的使用方式,并用伪类来模块化元素组件(例如表单或列表)

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>伪类选择器的使用</title>
  8. <style>
  9. /* 选择任何一个: :nth-of-type(n)
  10. 选择第一个: :first-of-type
  11. 选择最后一个: :last-of-type
  12. 选择倒数某一个: :nth-last-of-type()
  13. 唯一子元素的元素: :only-of-type */
  14. /* .list :nth-of-type(3) {
  15. background-color: lightgreen;
  16. }
  17. .list :first-of-type {
  18. background-color: red;
  19. }
  20. .list :last-of-type {
  21. background-color: blue;
  22. }
  23. .list > li:nth-last-of-type(3) {
  24. background-color: yellow;
  25. }
  26. ul li:only-of-type {
  27. background-color: yellow;
  28. } */
  29. @import url(css/list.css);
  30. </style>
  31. </head>
  32. <body>
  33. <ul class="list">
  34. <li>item1</li>
  35. <li>item2</li>
  36. <li>item3</li>
  37. <li>item4</li>
  38. <li>item5</li>
  39. <li>item6</li>
  40. </ul>
  41. <ul>
  42. <li>item</li>
  43. </ul>
  44. </body>
  45. </html>
  46. list.css文件
  47. /*伪类模块化列表*/
  48. .list :nth-of-type(3) {
  49. background-color: lightgreen;
  50. }
  51. .list :first-of-type {
  52. background-color: red;
  53. }
  54. .list :last-of-type {
  55. background-color: blue;
  56. }
  57. .list > li:nth-last-of-type(3) {
  58. background-color: yellow;
  59. }
  60. ul li:only-of-type {
  61. background-color: yellow;
  62. }

更多相关文章

  1. NestJs学习之旅(1)——快速开始
  2. 不使用宏的情况 Multi-Stage Word 也可让用户中马
  3. 磁盘文件系统损坏怎么解决?
  4. 利用 r2 逆向分析框架分析 Windows Minidumps
  5. 【exp/imp】将US7ASCII字符集的dmp文件导入到ZHS16GBK字符集的数
  6. 在MySQL中如何有效的删除一个大表?
  7. 【存储】裸设备和Oracle
  8. getExtension 获取文件名后缀
  9. Centos下SVN环境部署记录

随机推荐

  1. 6、linux网络编程--UDP协议编程
  2. 使用 logrotate 进行 nginx 日志分割
  3. 在KDE上导入Python的Gtk typelib
  4. 安装文件check_mk linux agent安装
  5. UNIX网络编程之源代码的编译和使用
  6. 在linux上获取已连接电视的电源状态
  7. mt7620的u-boot 代码
  8. linux audio(alsa) 驱动注册的简明流程.
  9. Linux常用命令(十) - nl
  10. linux抢占式调度