惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
D
Docker
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
J
Java Code Geeks
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Simon Willison's Weblog
Simon Willison's Weblog
S
Security Affairs
NISL@THU
NISL@THU
T
Tor Project blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
腾讯CDC
S
Schneier on Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
P
Privacy International News Feed
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
Vercel News
Vercel News
Cisco Talos Blog
Cisco Talos Blog
D
DataBreaches.Net
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
Latest news
Latest news
C
Check Point Blog
有赞技术团队
有赞技术团队
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
爱范儿
爱范儿
月光博客
月光博客
V
Vulnerabilities – Threatpost
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs

ImCaO's Blog

なんでもないや VuePress 2.0 中使用 Algolia DocSearch 文档搜索功能的配置 7 Years JustLaws 法律文库贡献指南 Love Story 阻止文明倒塌:Jonathan Blow 在莫斯科 DevGAMM 上的演讲 我做了一个法律文库,这可能是最简洁、便捷查询法律条文的地方 基本计算器问题的双栈通用解法 Spring Data Neo4j 开发记录 岛屿类问题的通用解法、DFS 遍历框架 When You're Gone 近况 很久以后 Spring Boot 自动配置原理 我怀念的 Webpack 核心概念 制造设备实时数据传输架构方案 暑假摸的鱼 夏至已至
CSS 选择器
ImCaO · 2021-05-11 · via ImCaO's Blog

以下介绍 10 种常用的 CSS 选择器

ID 选择器

# 号开头 + 自定名称

命名规则:首字符为英文字母(大小写皆可),第二个字符起可以是英文、数字、-_

例:#the-id-selector

作用:选取拥有 id 属性并且其值为 the-id-selector 的 HTML 元素

特性:id 在 HTML 页面中唯一

Class 选择器

. 号开头 + 自定名称

命名规则与 id 选择器相同

例:.my-class

作用:选取拥有 class 属性并且其值为 my-class 的 HTML 元素

特性:一个 class 可以用于多个 HTML 元素上,一个 HTML 元素可以设置多了 class 属性

Tag 选择器

直接使用 HTML 标签名

例:h1

作用:选中所有标签为 h1 的元素

在 Tag 选择器后加上 ID 选择器或 Class 选择器

例:div.container

作用:选中 class 属性为 container 的 div 元素

空格

例:.container div

作用:选中 class 属性为 container 的 HTML 元素里面的所有 div 元素,不包括 container 本身

>

例:.container > div

作用:选中 class 属性为 container 的 HTML 元素里面的第一层的 div 元素

+

例:.container + div

作用:选中与 class 属性为 container 的 HTML 元素处于同一层并紧接着的 div,如果紧接着的不是 div,则不会选中任何东西

~

例:.container ~ div

作用:选中与 class 属性为 container 的 HTML 元素处于同一层后面所有的 div

*

例:.container ~ *

作用:选中 class 属性为 container 的 HTML 元素处于同一层后面所有的元素

Attribute 选择器

例:a[title]

作用:选中所有拥有 title 属性的 a 元素

对属性值进行配对

例:a[href="https://www.google.com"]

作用:选中所有 href 属性为 https://www.google.com 的 a 元素

例:a[href^="https"]

作用:选中所有 href 属性开头为 https 的 a 元素

例:a[href$=".com"]

作用:选中所有 href 属性结尾为 .com 的 a 元素

例:a[href*="google"]

作用:选中所有 href 属性中包含 goolge 的 a 元素

属性值配对可用正则表达式

伪类 Pseudo Classes

例:a:hover

作用:设定鼠标移动到 a 元素上时候的样式

例:.container div:nth-child(2)

作用:选中 class 属性为 container 的 HTML 元素里面的第二个 div 元素

更多伪类的用法可参考文档

版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 ImCaO's Blog