一.选择器的优先级,id,class,tag

  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>层叠与优先级</title>
  8. <style>
  9. /* 1,1,3 */
  10. html body h1#first.active {
  11. color: palevioletred;
  12. }
  13. /* id选择器优先级大于class */
  14. /* 1,0,3 */
  15. html body h1#first {
  16. color: lightblue;
  17. }
  18. /* 1,0,2 */
  19. body h1#first {
  20. color: beige;
  21. }
  22. /* 选择器本身优先级大于书写顺序 */
  23. /* 样式类 */
  24. /* 0,1,2 */
  25. body h1.active {
  26. color: blue;
  27. }
  28. /* 0,1,1 */
  29. h1.active {
  30. color: yellow;
  31. }
  32. /* 标签选 */
  33. /* 0,0,3 */
  34. html body h1 {
  35. color: green;
  36. }
  37. /* 优先级相同时,书写顺序决定优先级 */
  38. /* 0,0,3 */
  39. html body h1 {
  40. color: red;
  41. }
  42. /* 样式类
  43. .active {
  44. color: blue;
  45. }*/
  46. /* #first {
  47. color: lightblue;
  48. }*/
  49. </style>
  50. </head>
  51. <body>
  52. <h1 class="active" id="first">Hello Woreld</h1>
  53. </body>
  54. </html>
  55. <!-- 公式:id >class >tag -->

二.前端组件样式模块化的原理与实现

mokuai

  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>模块化样式表</title>
  8. <link rel="stylesheet" href="css/index.css" />
  9. <!-- header { 1em=16px,3em=48px min-height: 3em; background-color: #ddd; }
  10. main { 1em=16px,3em=48px min-height: 20em; background-color: lightcyan; }
  11. footer { 1em=16px,3em=48px min-height: 3em; background-color: #999; }
  12. @import url(css/header.css); @import url(css/mian.css); @import
  13. url(css/footer.css);
  14. <style>
  15. @import url(css/index.css);
  16. </style> -->
  17. </head>
  18. <body>
  19. <header>页眉</header>
  20. <main>主体</main>
  21. <footer>页脚</footer>
  22. </body>
  23. </html>

三.常用伪类选择器的使用方式及伪类来模块化元素组件(表单、表格)

组件表单表格

  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>伪类选择器</title>
  8. <style>
  9. /* 结构伪类:选择子元素,只要有一个父元素作为查询起点 */
  10. /* .list > :nth-child(3) {
  11. background-color: violet;
  12. } */
  13. /* 匹配任何位置元素
  14. n = (0,1,2,3,4.....) */
  15. /* .list > li:nth-child(0n + 3) {
  16. background-color: violet;
  17. } */
  18. /* 分组伪类结构选择器,推荐使用 */
  19. .list > li:nth-of-type(3) {
  20. background-color: cyan;
  21. }
  22. /* 选择中第一个p /li */
  23. .list > p:nth-of-type(1) {
  24. background-color: lightgreen;
  25. }
  26. .list > li:nth-of-type(1) {
  27. background-color: lightgreen;
  28. }
  29. .list > li:nth-of-type(7) {
  30. background-color: green;
  31. }
  32. /* 最后一个p */
  33. .list > p:nth-of-type(3) {
  34. background-color: red;
  35. }
  36. .list p:last-of-type {
  37. background-color: blue;
  38. }
  39. .list p:first-of-type {
  40. background-color: red;
  41. }
  42. /* 选择倒数第三个 */
  43. .list > li:nth-last-of-type(3) {
  44. background-color: yellow;
  45. }
  46. ul > li:only-of-type {
  47. background-color: turquoise;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <ul class="list">
  53. <li>item1</li>
  54. <li>item2</li>
  55. <li>item3</li>
  56. <li>item4</li>
  57. <li>item5</li>
  58. <li>item6</li>
  59. <p>item7</p>
  60. <p>item8</p>
  61. <li>item9</li>
  62. <p>item10</p>
  63. </ul>
  64. <ul>
  65. <li>item</li>
  66. </ul>
  67. </body>
  68. <!-- 选择任何一个:nth-of-type(n) 选择第一个:first-of-type
  69. 选择最后一个:last-of-type 选择倒数某一个:nth-last-of-type(n)
  70. 选择唯一子元素得元素:only-of-type-->
  71. </html>
  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>组件化编程思想t</title>
  8. <style>
  9. /* 只有获取到页面中得某个元素组件得入口,
  10. 再根据子元素得位置,使用伪类就可以选择任何一个元素了 */
  11. /* 选择首页 */
  12. /* .index {
  13. background-color: yellow;
  14. } */
  15. /* menu是入口 */
  16. /* .menu :first-of-type {
  17. background-color: tomato;
  18. }
  19. .menu :last-of-type {
  20. background-color: turquoise;
  21. }
  22. .menu :nth-last-of-type(2) {
  23. background-color: yellow;
  24. }
  25. .menu :nth-last-of-type(3) {
  26. background-color: turquoise;
  27. } */
  28. @import url(css/menu.css);
  29. @import url(css/login.css);
  30. /* 只要获取表单得入口,使用伪类可以获取表单中任何一个控件 */
  31. /* 获取到提交按钮 */
  32. /* .login button {
  33. background-color: turquoise;
  34. color: black;
  35. } */
  36. /* .login :only-of-type {
  37. background-color: green;
  38. color: black;
  39. }
  40. .login :first-of-type {
  41. background-color: burlywood;
  42. color: black;
  43. }
  44. .login :nth-last-of-type(2) {
  45. background-color: blanchedalmond;
  46. color: black;
  47. }
  48. .login :nth-of-type(3) {
  49. background-color: red;
  50. color: black;
  51. } */
  52. </style>
  53. </head>
  54. <body>
  55. <nav class="menu">
  56. <a href="">首页</a>
  57. <a href="">视频</a>
  58. <a href="">下载</a>
  59. <a href="">注册/登录</a>
  60. </nav>
  61. <hr />
  62. <form action="" style="display: grid; gap: 1rem" class="login">
  63. <input type="text" placeholder="username" />
  64. <input type="password" placeholder="password" />
  65. <input type="email" placeholder="demo@email" />
  66. <button>提交</button>
  67. </form>
  68. </body>
  69. </html>

更多相关文章

  1. 选择器优先级/前端组件样式模块化原理与实现/常用伪类选择器的使
  2. 0322作业
  3. css基础:简单的选择器、伪类选择器与前端组件样式模块化知识
  4. 0322作业-css基本语法、选择器及模块化开发
  5. css基础、选择器、模块化组件
  6. 【CSS入门】CSS基本语法和选择器优先级学习总结简介
  7. 伪类选择器,优先级,模块化
  8. CSS3选择器 :nth-child()的用法
  9. 选择云服务器的5个要素:性能、安全性、稳定性、价格、生态

随机推荐

  1. android 底部菜单
  2. android之【TableLayout布局】
  3. cocos2dx android mac
  4. Android 文件下载 downloadManager
  5. android 作业1相对布局(拼图)
  6. android之实现SeekBar拖动组件
  7. EditText设置不自动弹出键盘
  8. android桌面快捷方式添加 删除 更新 自动
  9. MediaScannerReceiver
  10. 2011.07.18——— android AlphaBitmap