css的伪类有哪些?
同一个标签,根据其不同的种状态,有不同的样式。这就叫做“伪类”。伪类用冒号来表示。css 伪类用于向某些选择器添加特殊的效果。
css伪类:
| :active | :any-link | :blank | :checked | :current | :default |
| :defined | :dir() | :disabled | :drop | :empty | :enabled |
| :first | :first-child | :first-of-type | :fullscreen | :future | :focus |
| :focus-visible | :focus-within | :has() | :host | :host() | :host-context() |
| :hover | :indeterminate | :in-range:invalid | :is() | :lang() | :last-child |
| :last-of-type | :left | :link | :local-link | :not() | :nth-child() |
| :nth-col() | :nth-last-child() | :nth-last-col() | :nth-last-of-type() | :nth-of-type() | :only-child |
| :only-of-type | :optional | :out-of-range | :past | :placeholder-shown | :read-only |
| :read-write | :required | :right | :root | :scope | :target |
| :target-within | :user-invalid | :valid | :visited | :where() |
伪类的语法:
selector : pseudo-class {property: value}CSS 类也可与伪类搭配使用。
selector.class : pseudo-class {property: value}伪类连同伪元素一起,他们允许你不仅仅是根据文档 dom 树中的内容对元素应用样式,而且还允许你根据诸如像导航历史这样的外部因素来应用样式(例如 :visited)。
同样的,可以根据内容的状态(例如在一些表单元素上的 :checked),或者鼠标的位置(例如 :hover 让你知道是否鼠标在一个元素上悬浮)来应用样式。
本文内容仅供个人学习/研究/参考使用,不构成任何决策建议或专业指导。分享/转载时请标明原文来源,同时请勿将内容用于商业售卖、虚假宣传等非学习用途哦~感谢您的理解与支持!