CSS选择器(基本选择器,结构选择器,属性选择器, 伪类选择器)

CSS选择器

基本选择器和结构选择器
选择器示例描述
.class.testclass选择 class="testclass " 的所有元素
#id#testid选择 id=“testid” 的所有元素
**选择所有元素
elementp选择所有p元素
element,elementdiv,p选择所有元素和所有p元素
element elementdiv p选择div内部的所有后代是p的元素
element>elementdiv>p选择div所有子元素为p的元素
element+elementdiv+p选择紧接在div元素之后的所有p元素
属性选择器
选择器示例描述
[attribute][target]带有 target 属性所有元素
[attribute=value][target=_blank]targe 属性 等于"_blank" 的所有元素
[attribute~=value][title~=test]title 属性包含单词 “test” 的所有元素
[attribute=value][title=cs]title 属性值为 "cs"的单词,或cs-go 以-连接的的独立单词
[attribute*=value]a[src*=“test”]src 属性中包含 “test” 子串的每个 元素
[attribute^=value]a[src^=“https”]src 属性值以 “https” 开头的每个 元素
[attribute$=value]a[src$=".jpeg"]src 属性以 “.jpeg” 结尾的所有 元素
伪类选择器
状态示例说明
:linka:link选择所有未被访问的链接
:visiteda:visited选择所有已被访问的链接
:hovera:hover鼠标移动到元素上时
:activea:active点击正在发生时
:focusinput::focus选择获得焦点的 input 元素
:root:root选择文档的根元素即html。
:emptyp:empty
:first-childp:first-child
:last-childp:last-child
:first-of-typep:first-of-type
:last-of-typep:last-of-type
:only-of-typep:only-of-type
:only-childp:only-child
:nth-child(n)p:nth-child(2)
:nth-child(odd)p:nth-child(odd)
:nth-child(even)p:nth-child(even)
:nth-of-type(n)p:nth-of-type(2)
:nth-last-child(n)p:nth-last-child(2)
:nth-last-of-type(n)p:nth-last-of-type(2)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值