博客列表 >伪类选择器,媒体查询,box-sizing属性

伪类选择器,媒体查询,box-sizing属性

可乐
可乐原创
2021年09月25日 16:39:51339浏览

伪类选择器

  1. <ul class="list">
  2. <li>bread1</li>
  3. <li>bread2</li>
  4. <li>bread3</li>
  5. <li>bread4</li>
  6. <li>
  7. bread5
  8. <ul>
  9. <li>bread5-1</li>
  10. <li>bread5-2</li>
  11. <li>bread5-3</li>
  12. <li>bread5-4</li>
  13. <li>bread5-5</li>
  14. </ul>
  15. </li>
  16. <li>bread6</li>
  17. <li>bread7</li>
  18. <li>bread8</li>
  19. </ul>
  20. <style>
  21. /* 第四个 (空格,递归)*/
  22. .list :nth-of-type(4) {
  23. background-color: rgb(30, 3, 54);
  24. }
  25. /* 第二个*/
  26. .list > :nth-of-type(2) {
  27. background-color: rgb(238, 42, 238);
  28. }
  29. /* 第一个 */
  30. .list > :first-of-type {
  31. background-color: rgb(156, 87, 87);
  32. }
  33. /* 第六个 */
  34. .list > :nth-of-type(6) {
  35. background-color: rgb(73, 14, 73);
  36. }
  37. /* 最后一个子元素 */
  38. .list > :last-of-type {
  39. background-color: rgb(99, 99, 42);
  40. }
  41. /* 第五个 */
  42. .list > :nth-of-type(5) {
  43. background-color: rgb(155, 148, 155);
  44. }
  45. /* 第五个是不是倒数第4个 */
  46. .list > li:nth-last-of-type(4) {
  47. background-color: rgb(20, 100, 100);
  48. }
  49. </style>

效果图

伪类选择器的参数

  1. <ul class="list">
  2. <li>bread</li>
  3. <li>bread2</li>
  4. <li>bread3</li>
  5. <li>bread4</li>
  6. <li>bread5</li>
  7. <li>bread6</li>
  8. <li>bread7</li>
  9. <li>bread8</li>
  10. </ul>
  11. <style>
  12. /* 前两个个 */
  13. .list > :nth-of-type(-n + 2) {
  14. background-color: rgb(174, 189, 236);
  15. }
  16. /* -1 * 0 + 2 = 2
  17. -1 *1 + 2 = 1
  18. -1 *2 + 2 = 0 (匹配结束)*/
  19. /* 后两个个 */
  20. .list > :nth-last-of-type(-n + 2) {
  21. background-color: rgb(155, 6, 68);
  22. }
  23. /* 正数第五个*/
  24. .list > :nth-of-type(5) {
  25. background-color: rgb(236, 158, 180);
  26. }
  27. /*偶数*/
  28. .list > :nth-of-type(2n){
  29. background-color: rgb(231, 240, 111);
  30. }
  31. html {
  32. background-color: rgb(241, 241, 10);
  33. }
  34. /* :root === html */
  35. :root {
  36. background-color: rgb(17, 235, 17);
  37. }
  38. </style>
  39. <input type="text" />
  40. <input type="text" disabled />
  41. <style>
  42. input:disabled {
  43. background-color: rgb(82, 82, 5);
  44. }
  45. input:enabled {
  46. background-color: rgb(38, 126, 126);
  47. }
  48. </style>
  49. /* 媒体: 屏幕, 打印机 */
  50. /* 查询: 查询当前屏幕宽度变化 */
  51. /* 移动优先,从最小的屏幕开始进行媒体查询 */
  52. /* 桌面优先/PC优先, 由大屏到小屏 */
  53. /* 只要动态的改变rem的大小, 可以动态的调整每个按钮的大小 */

效果图

媒体查询

  1. </style>
  2. <body>
  3. <button class="btn small">按钮A</button>
  4. <button class="btn middle">按钮B</button>
  5. <button class="btn large">按钮C</button>
  6. /*
  7. <style>
  8. html {
  9. font-size: 15px;
  10. }
  11. /* 基本样式 */
  12. .btn {
  13. background-color: rgb(16, 218, 103);
  14. color: rgb(83, 31, 31);
  15. border: none;
  16. outline: none;
  17. }
  18. .btn:hover {
  19. cursor: pointer;
  20. opacity: 0.8;
  21. transition: 0.3s;
  22. }
  23. /* 小按钮 */
  24. .btn.small {
  25. font-size: 2.2rem;
  26. padding: 0.3rem 0.6rem;
  27. }
  28. /* 中按钮 */
  29. .btn.middle {
  30. font-size: 3.3rem;
  31. padding: 0.3rem 0.6rem;
  32. }
  33. /* 大按钮 */
  34. .btn.large {
  35. font-size: 5.5rem;
  36. padding: 0.3rem 0.6rem;
  37. }
  38. /* 移动优先,从最小的屏幕开始进行媒体查询 */
  39. @media (min-width: 540px) {
  40. html {
  41. font-size: 10px;
  42. }
  43. }
  44. @media (min-width: 630px) {
  45. html {
  46. font-size: 15px;
  47. }
  48. }
  49. @media (min-width: 750px) {
  50. html {
  51. font-size: 20px;
  52. }
  53. }
  54. /* 桌面优先/PC优先, 由大屏到小屏 */
  55. @media (max-width: 740px) {
  56. html {
  57. font-size: 20px;
  58. }
  59. }
  60. @media (max-width: 660px) {
  61. html {
  62. font-size: 17px;
  63. }
  64. }
  65. @media (max-width: 490px) {
  66. html {
  67. font-size: 14px;
  68. }
  69. }
  70. @media (min-width: 740px) {
  71. html {
  72. font-size: 16px;
  73. }
  74. }
  75. @media (min-width: 480px) and (max-width: 640px) {
  76. body {
  77. background-color: rgb(29, 48, 226);
  78. }
  79. }
  80. </style>

效果图

Box-sizing

  1. <div class="img"><img src="cake.PNG" /></div>
  2. </body>
  3. <style>
  4. .img {
  5. width: 200px;
  6. height: 200px;
  7. border: 10px solid rgb(174, 235, 8);
  8. padding: 0px;
  9. }
  10. </style>
  11. <div class="img1"><img src="cake.PNG" /></div>
  12. <style>
  13. .img1 {
  14. width: 200px;
  15. height: 200px;
  16. border: 10px solid rgb(174, 235, 8);
  17. padding: 10px 20px;
  18. }
  19. </style>
  20. <div class="img2"><img src="cake.PNG" /></div>
  21. <style>
  22. .img2 {
  23. width: 200px;
  24. height: 200px;
  25. border: 10px solid rgb(174, 235, 8);
  26. padding: 10px 20px 30px 40px;
  27. }
  28. </style>

效果图

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议