From f2c3b540e2e73297d9d65a2b4f62539ba784e6b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E6=9D=A8=E6=82=A6?= <14091313+ding-yangyue@user.noreply.gitee.com> Date: Mon, 14 Oct 2024 19:44:15 +0800 Subject: [PATCH 1/2] 10.14 --- .../20241014 css\344\274\252\347\261\273.md" | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 "\344\270\201\346\235\250\346\202\246/20241014 css\344\274\252\347\261\273.md" diff --git "a/\344\270\201\346\235\250\346\202\246/20241014 css\344\274\252\347\261\273.md" "b/\344\270\201\346\235\250\346\202\246/20241014 css\344\274\252\347\261\273.md" new file mode 100644 index 00000000..08d955f3 --- /dev/null +++ "b/\344\270\201\346\235\250\346\202\246/20241014 css\344\274\252\347\261\273.md" @@ -0,0 +1,212 @@ +### 伪类 +1. 链接伪类: +* :link:用于未被访问的链接。 +* :visited:用于已被访问的链接。 +* :hover:鼠标悬停在元素上时。 +* :active:当元素被激活(如点击)时。 + +示例代码: +```` +css +a:link { + color: green; +} +a:visited { + color: purple; +} +a:hover { + color: red; +} +a:active { + color: yellow; +} +```` + +2. 结构伪类: +* :first-child:选择作为其父元素的第一个子元素的元素。 +* :last-child:选择作为其父元素的最后一个子元素的元素。 +* :nth-child():选择父元素中的特定位置的子元素。 +* :nth-last-child():从父元素的末尾开始选择特定位置的子元素。 +* :first-of-type:选择作为其父元素的第一个特定类型的子元素。 +* :last-of-type:选择作为其父元素的最后一个特定类型的子元素。 +* :nth-of-type():选择父元素中的特定位置的特定类型的子元素。 +* :nth-last-of-type():从父元素的末尾开始选择特定位置的特定类型的子元素。 +* :only-child:选择是其父元素的唯一子元素的元素。 +* :only-of-type:选择是其父元素的唯一特定类型的子元素。 + +示例代码: +```` +css +p:first-child { + font-weight: bold; +} +li:nth-child(2) { + color: blue; +} +```` + +3. 状态伪类: +* :checked:用于单选按钮、复选框或选项按钮被选中时。 +* :disabled:用于禁用的表单元素。 +* :enabled:用于启用的表单元素。 +* :required:用于设置了 required 属性的表单元素。 +* :optional:用于没有设置 required 属性的表单元素。 +* :valid:用于输入值有效的表单元素。 +* :invalid:用于输入值无效的表单元素。 +* :in-range:用于输入值在指定范围内的表单元素。 +* :out-of-range:用于输入值不在指定范围内的表单元素。 + +示例代码: +```` +css +input:checked { + background-color: lightgray; +} +input:disabled { + background-color: lightgray; +} +```` + +4. 否定伪类: +* :not():否定一个选择器,表示不选择匹配该选择器的元素。 + +示例代码: +```` +css +p:not(:first-child) { + color: gray; +} +```` + +5. 目标伪类: +* :target:用于页面上被锚点指向的元素。 + +示例代码: +```` +css +section:target { + background-color: yellow; +} +```` + +6. 语言伪类: +* :lang():用于根据元素的 lang 属性选择元素。 + +示例代码: +```` +css +p:lang(en) { + color: blue; +} +```` + +7. 动态伪类: +:nth-child() 和 :nth-of-type() 可以结合 odd 和 even 关键字使用,选择奇数或偶数位置的子元素。 + +示例代码: +```` +css +li:nth-child(odd) { + background-color: lightgray; +} +li:nth-child(even) { + background-color: white; +} +```` + +## 作业 +1. 出CSS规则,使得.main类中的
元素中的所有

标签的字体变为粗体,并且