博客列表 >结构伪类与状态伪类 ,实例演示盒模型常用属性,

结构伪类与状态伪类 ,实例演示盒模型常用属性,

杨雨辰
杨雨辰原创
2022年08月04日 01:48:42418浏览

结构伪类选择器

  1. /* 结论:
  2. a = 0: 选中单个匹配。
  3. a = 1: 正向,向下匹配。
  4. a = -1:反向,向上匹配。
  5. a = 2:获取奇偶(2n = 偶数 2n-1等于奇数) */
  6. /* 语法糖:even=偶数 odd=奇数 last=最后一个 属性名 + of-type=选中一个 */
  7. /* .list > li.first {
  8. background-color: bisque;
  9. } */
  10. /* 当前是获取的第一个子元素 后代选择器写法 */
  11. /* .list > li:nth-of-type(1) {
  12. background-color: blue;
  13. } */
  14. /* 当前是获取第一个子元素,伪类选择器的写法 */
  15. /* 伪类选择器 nth-of-type */
  16. /* .list li:nth-of-type(4) {
  17. background-color: rgb(123, 62, 62);
  18. } */
  19. /* nth-ofo-type(an+b)
  20. 1.a:系数,[0,1,2,3,4...]
  21. 2.n:参数,[0,1,2,3,4...]
  22. 3.b:偏移量,从0开始
  23. 注意:计算出来的索引,必须是有效的,而且必须从1开始
  24. */
  25. /* 选择元素有两种情况:
  26. 1.选择一个
  27. 2.选择一组 */
  28. /*
  29. 匹配一个:a = 0 完整语法 :
  30. a=0是选一个
  31. .list li:nth-of-type(0n + 1) {
  32. background-color: rgb(60, 27, 27);
  33. }
  34. /* 计算方式an+b为计算结果
  35. 匹配第
  36. 因为a=0 0*任何数都等于0 例如0n+1=0+1=1 所以可以不写 直接写b(即可)
  37. .list li:nth-of-type(1) {
  38. background-color: rgb(196, 118, 118);
  39. } */
  40. /* 匹配一组 a = 1 */
  41. /* b不写就从0开始递增 */
  42. /* 1n=从0开始选中全部 */
  43. /* .list li:nth-of-type(1n) {
  44. background-color: aqua;
  45. }*/
  46. /* 1乘以任何不变,那么b开始递增
  47. 1. 1*n + 0 = 0
  48. 2. 1*n + 1 = 1
  49. 3. 1*n + 2 = 2
  50. 4. 1*n + 3 = 3
  51. 。。。
  52. 最终得到一个索引顺序 1,2,3,4,5,6,7,8
  53. */
  54. /* 1n+0 :从0开始匹配, 1n = 1n+0
  55. 1n+3:从第3个开始匹配
  56. 1n+6:从第6个开始匹配 */
  57. /* .list li:nth-of-type(1n + 5) {
  58. background-color: rgb(82, 115, 10);
  59. }
  60. /* a = -1:反向匹配 */
  61. /* .list li:nth-of-type(-n + 2) {
  62. background-color: rgb(227, 29, 197);
  63. } */
  64. /* :nth-last-of-type(1n+1)从倒数第一个开始选中 last倒序 */
  65. /* .list li:nth-last-of-type(1n + 3) {
  66. background-color: rgb(125, 91, 91);
  67. } */
  68. /* 2n-1选中奇数 */
  69. /* .list li:nth-of-type(2n-1) {
  70. background-color: rgb(129, 37, 37);
  71. } */
  72. /* 2n-2选中偶数 */
  73. /* .list li:nth-of-type(2n-2) {
  74. background-color: rgb(129, 37, 37);
  75. } */

状态伪类

  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. </head>
  9. <body>
  10. <form action="reds.php">
  11. <!-- 表单分组 -->
  12. <fieldset>
  13. <legend>用户注册</legend>
  14. <label for="uname">用户名</label>
  15. <input
  16. type="text"
  17. id="uname"
  18. placeholder="用户名不能为空"
  19. name="username"
  20. />
  21. <br />
  22. <!-- 提示 -->
  23. <label for="tips" aria-disabled="false">警告:</label>
  24. <input
  25. type="text"
  26. id="tips"
  27. value="注册后禁止注销"
  28. disabled
  29. style="border: none"
  30. />
  31. <div class="gender">
  32. <label for="m">性别</label>
  33. <input type="radio" name="sex" id="m" value="0" checked />
  34. <label for="m"></label>
  35. <input type="radio" name="sex" id="f" value="1" />
  36. <label for="f"></label>
  37. <br />
  38. <button>提交</button>
  39. </div>
  40. </fieldset>
  41. </form>
  42. <style>
  43. /* 获取被禁用的元素 */
  44. input:disabled {
  45. color: blue;
  46. }
  47. /* 获取到被默认选中的单选按钮 */
  48. input:checked + label {
  49. color: blue;
  50. }
  51. /* 获取焦点的变化 */
  52. button:hover {
  53. cursor: pointer;
  54. background-color: rgb(102, 102, 131);
  55. }
  56. </style>
  57. </body>
  58. </html>

盒模型

  1. <title>盒模型、框模型</title>
  2. </head>
  3. <body>
  4. <div class="box">
  5. <!-- margin:外边距 border:边框 padding:内边框 conetnt:内容区 -->
  6. </div>
  7. <style>
  8. .box {
  9. height: 200px;
  10. width: 200px;
  11. border: 2px solid;
  12. /* padding:内边框 是内容区与边框之间的填充区域 */
  13. /* margin:外边距,控制当前盒子与其他元素之间的空隙 */
  14. /* 不可见属性:margin , padding s只能设置宽度,不能设置样式*/
  15. /* box-sizing: border-box;推荐的盒子计算方式,可以简化页面布局
  16. box-sizing: contetnt-box 还原到w3c默认标准的计算方式*/
  17. /* init.css文件一般为样式初始化; */
  18. /* .box {
  19. 宽度 样式 前景色
  20. border-top: 5px dashed blue;
  21. border-left: 5px dashed blue;
  22. border-right: 5px dashed blue;
  23. border-bottom: 5px dashed darkblue;
  24. } */
  25. /* padding与border一样 可简化书写简化方案:顺时针方向
  26. 1.四值:顺时针,上 右 下 左
  27. padding: 5px 10px 15px 20px;
  28. 2.三值 双值:第2个永远表示左右
  29. padding:5px 10px 15px
  30. 3.双值: 第一个上下,第2个左右
  31. padding:5px 10*/
  32. }

盒子模型

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