- CSS 教程
- CSS 简介
- CSS 选择器
- CSS 默认值
- CSS 注释
- CSS 字体
- CSS 字号
- CSS 单位
- CSS 颜色
- CSS 背景
- CSS 高级教程
- CSS 动画
- CSS 伪类
- CSS 伪元素
- CSS 计数器
- CSS 特异位
- CSS 清除浮动
- CSS 图像精灵
- CSS 性能优化
- CSS 属性
- CSS align-content
- CSS align-items
- CSS align-self
- CSS all
- CSS animation
- CSS animation-delay
- CSS animation-direction
- CSS animation-duration
- CSS animation-fill-mode
- CSS animation-iteration-count
- CSS animation-name
- CSS animation-play-state
- CSS animation-timing-function
- CSS backface-visibility
- CSS background
- CSS background-attachment
- CSS background-blend-mode
- CSS background-clip
- CSS background-color
- CSS background-image
- CSS background-origin
- CSS background-position
- CSS background-repeat
- CSS background-size
- CSS border
- CSS border-bottom
- CSS border-bottom-color
- CSS border-bottom-left-radius
- CSS border-bottom-right-radius
- CSS border-bottom-style
- CSS border-bottom-width
- CSS border-collapse
- CSS border-color
- CSS border-image
- CSS border-image-outset
- CSS border-image-repeat
- CSS border-image-slice
- CSS border-image-source
- CSS border-image-width
- CSS border-left
- CSS border-left-color
- CSS border-left-style
- CSS border-left-width
- CSS border-radius
- CSS border-right
- CSS border-right-color
- CSS border-right-style
- CSS border-right-width
- CSS border-spacing
- CSS border-style
- CSS border-top
- CSS border-top-color
- CSS border-top-left-radius
- CSS border-top-right-radius
- CSS border-top-style
- CSS border-top-width
- CSS border-width
- CSS bottom
- CSS box-shadow
- CSS box-sizing
- CSS caption-side
- CSS caret-color
- CSS @charset
- CSS clear
- CSS clip
- CSS clip-path
- CSS color
- CSS column-count
- CSS column-fill
- CSS column-gap
- CSS column-rule
- CSS column-rule-color
- CSS column-rule-style
- CSS column-rule-width
- CSS column-span
- CSS column-width
- CSS columns
- CSS content
- CSS counter-increment
- CSS counter-reset
- CSS cursor
- CSS direction
- CSS display
- CSS empty-cells
- CSS filter
- CSS flex
- CSS flex-basis
- CSS flex-direction
- CSS flex-flow
- CSS flex-grow
- CSS flex-shrink
- CSS flex-wrap
- CSS float
- CSS font
- CSS @font-face
- CSS font-family
- CSS font-kerning
- CSS font-size
- CSS font-size-adjust
- CSS font-stretch
- CSS font-style
- CSS font-variant
- CSS font-weight
- CSS grid
- CSS grid-area
- CSS grid-auto-columns
- CSS grid-auto-flow
- CSS grid-auto-rows
- CSS grid-column
- CSS grid-column-end
- CSS grid-column-gap
- CSS grid-column-start
- CSS grid-gap
- CSS grid-row
- CSS grid-row-end
- CSS grid-row-gap
- CSS grid-row-start
- CSS grid-template
- CSS grid-template-areas
- CSS grid-template-columns
- CSS grid-template-rows
- CSS height
- CSS hyphens
- CSS @import
- CSS justify-content
- CSS @keyframes
- CSS left
- CSS letter-spacing
- CSS line-height
- CSS list-style
- CSS list-style-image
- CSS list-style-position
- CSS list-style-type
- CSS margin
- CSS margin-bottom
- CSS margin-left
- CSS margin-right
- CSS margin-top
- CSS max-height
- CSS max-width
- CSS @media
- CSS min-height
- CSS min-width
- CSS object-fit
- CSS object-position
- CSS opacity
- CSS order
- CSS outline
- CSS outline-color
- CSS outline-offset
- CSS outline-style
- CSS outline-width
- CSS overflow
- CSS overflow-x
- CSS overflow-y
- CSS padding
- CSS padding-bottom
- CSS padding-left
- CSS padding-right
- CSS padding-top
- CSS visibility
- CSS white-space
- CSS width
- CSS word-break
- CSS word-spacing
- CSS word-wrap
- CSS writing-mode
- CSS z-index
- CSS 参考手册
CSS 选择器
CSS 选择器是用于选择 HTML(或XML)文档中特定元素的模式。它们允许开发者根据元素的类型、属性、状态等来定义样式或应用行为。
常见的CSS选择器包括:
1、元素选择器:选择指定类型的所有元素。例如,p选择所有段落元素。
p { /* styles */ }
2、类选择器:选择具有特定类的元素。类选择器以点号开头(.)。
.my-class { /* styles */ }
3、ID选择器:选择具有特定id的唯一元素。ID选择器以井号开头(#)。
#my-id { /* styles */ }
4、属性选择器:选择具有特定属性的元素,可以进一步指定属性值。
[type="text"] { /* styles */ }
5、伪类选择器:选择处于特定状态的元素,例如链接的状态(:hover、:visited等)。
a:hover { /* styles */ }
6、伪元素选择器:用于选中元素的特定部分,如元素的第一行(::first-line)或最后一个字母(::last-letter)。
p::first-line { /* styles */ }
7、组合选择器:使用多个选择器组合来选择特定的元素,以逗号分隔。
h1, h2, h3 { /* styles */ }
8、后代选择器:选择作为另一个元素后代的元素。后代选择器使用空格分隔。
div p { /* styles */ }
这些选择器可以单独使用或结合在一起,以精确地指定要样式化或操作的HTML元素。CSS 选择器是CSS 规则中非常强大和灵活的部分,使得开发者能够高度定制网页的外观和行为。