本文为阅读MDN文档笔记

目录

Different types of Selectors

  1. Simple selectors: Match one or more elements based on element type, class or id(还有通用选择器).

  2. Attribute selectors: Match one or more elements based on their attributes/attribute values.

  3. Pseudo-classes(伪类): Match one or more elements that exist in a certain state, such as an element that is being hovered over by the mouse pointer, or a checkbox that is currently disabled or checkd, or an element that is the first child of its parent in the DOM tree.

  4. Preudo-elements(伪元素): Match one or more parts of content that are in a certain position in relation to an element, for example the first word of each paragraph, or generated content appearing just before an element.(for example: :first-letter, :first-line, :before, :after)

  5. Combinators(关系选择器): These are not exactly selectors themselves, but ways of combining two or more selectors in useful ways for very specific selections.So for example, you could select only paragraphs that are direct descendants of divs, or paragraphs that come directly after headings.

  6. Multiple selectors(多重选择器): Again, these are not separate selectors;the idea is that you can put multiple selectors on the same CSS rule, separated by commas(逗号), to apply a single set of declarations to all the elements selectd by those seletors.

Attribute Selectors

Attribute selectors can ben divided into two categories depending on the way they match attribute values: Presence value attribute selectors and Substring value attribute selectors.

Presence and value attribute selectors

These attribute selectors try to match an exact attribute value:

1. [attr]: This selector will select all elements with the attribute attr, whatever its value.

2. [attr=val]: This selector will select all elements with the attribute attr, but only if its value is val.

3. [attr~=val]: This selector will select all elements with the attribute attr, but only if the value val is one of a space-separated list of values contained in attr's value, for example a single class in a space-separated list of classes.

Substring and value attribute selectors

Attribute selectors in this class are also known as "RegExp-like selectors", because they offer flexible matching in a similar fashion to regular expression(but to be clear, these selectors are not true regular expressions):

1. [attr|=val]: This selector will select all elements with the attribute attr for which the value is exactly val or starts with val-.

2. [attr^=val]: This selector will select all elements with the attribute attr for which the value starts with val.

3. [attr$=val]: This selector will select all elements with the attribute attr for which the value ends with val.

4. [attr*=val]: This selector will select all elements with the attribute attr for which the value contains the string val(unlike [attr~=val]), this selector doesn't treat spaces as value separators but as part of the attribute value.)

Pseudo-selectors

Pseudo-slelectors, they don't select actual elements, but rather certain parts of elements, or elements only in certain contexts.They come in two main types --- pseudo-classes and pseudo-elements.

Pseudo-classes

:active
:any
:checked
:default
:dir()
:disabled
:empty
:first
:first-child
:first-of-type
:fullscreen
:focus
:hover
:indeterminate
:in-range
:invalid
:lang()
:last-child
:last-of-type
:left
:link
:not()
:nth-child()
:nth-last-child()
:nth-last-of-type()
:nth-of-type()
:only-child
:only-of-type
:optional
:out-of-range
:read-only
:read-write
:required
:right
:root
:scope
:target
:valid
:visited

Pseudo-elements

::after
::before
::first-letter
::first-line
::selection
::backdrop

Combinators

We'll explore combinators and multiple selectors --- two ways of combining multiple selectors together for futher useful selection capabilities.

  1. AB: Any element matching both A and B at the same time.

  2. A B: Any element matching B is a descendant(子孙) of an element matching A(that is: a child, or a child of a child, etc.)

  3. A > B: Any element matching B that is a direct child of an element matching A.

  4. A + B: Any element matching B that is the next sibling of an element matching A(that is: the next child of the same parent.)

  5. A ~ B: Any element matching B that is among the next sibling of an element matching A(that is: one of the next children of the same parent.)

阅读MDN文档之CSS选择器介绍(一)的更多相关文章

  1. 阅读MDN文档之StylingBoxes(五)

    目录 BoxModelRecap Box properties Overflow Background clip Background origin Outline Advanced box prop ...

  2. 阅读MDN文档之布局(四)

    Introducing positioning Static positioning Relative positioning Introducing top, bottom, left and ri ...

  3. 阅读MDN文档之基本盒模型(三)

    Box properties Margin collapsing Adjacent siblings(相邻兄弟) Parent and first/last child Empty blocks Ac ...

  4. 阅读MDN文档之布局(四)

    Introducing positioning Static positioning Relative positioning Introducing top, bottom, left and ri ...

  5. 阅读MDN文档之层叠与继承(二)

    目录 The cascade Importance Specificity Source order A note on rule mixing Inheritance Controlling inh ...

  6. 前端开发必备之MDN文档

    想下载MDN文档的看前面的内容就可以了. HTML 源码下载 MDN官方下载地址:https://developer.mozilla.org/media/developer.mozilla.org.t ...

  7. Winform开发框架中的内容及文档管理模块功能介绍

    在开发项目的时候,我们有一些场景需要编辑一些HTML文档,作为内容发布系统的一部分,有时候也需要对一些文档如WORD文档进行编辑管理,这样需要我们对这些内容及文档进行合适的管理.本文主要介绍在WInf ...

  8. Emacs阅读chm文档

    .title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium ...

  9. MDN 文档高级操作进阶教程

    MDN 文档高级操作进阶教程 MDN 文档, 如何优雅的使用 MDN 文档上的富文本编辑器 pre & 语法高亮器 code & note box source code 上传附件 i ...

随机推荐

  1. 离开Visual Studio C#的编译(你不知道的C#)

    很多人一开始学习.net 第一天必定是安装Visual studio 或者很多关于C#学习的书上第一章节必定是告诉你要你下载一个vs 其实没有vs未必就不能开发了,只是可能说vs给我的开发带来了很多的 ...

  2. HDU3792---Twin Prime Conjecture(树状数组)

    Twin Prime Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. 项目实战8—tomcat企业级Web应用服务器配置与会话保持

    tomcat企业级Web应用服务器配置与实战 环境背景:公司业务经过长期发展,有了很大突破,已经实现盈利,现公司要求加强技术架构应用功能和安全性以及开始向企业应用.移动APP等领域延伸,此时原来开发w ...

  4. Android破解学习之路(二)——Android游戏 滚动的天空破解

    经过上一期的破解教程,相信大家跟我一样都是对破解是初入门,我们破解的目的是什么? 赚钱吗?百度上一大堆破解版的应用,破解的人有赚到钱吗?实实在在的说,其实也是方便自己而已. 玩个游戏,感觉过不去了,来 ...

  5. javascript设计模式——策略模式

    前面的话 在程序设计中,常常遇到类似的情况,要实现某一个功能有多种方案可以选择.比如一个压缩文件的程序,既可以选择zip算法,也可以选择gzip算法.这些算法灵活多样,而且可以随意互相替换.这种解决方 ...

  6. 《跟我学IDEA》一、下载安装idea,设置背景字体编码,配置JDK

    写在前面的话:作为一个在IT界摸爬滚打6年+的老程序员,我属于会的东西多而杂,但是没有任何一样精通的.曾经自己也认真过,蹉跎过,最近和别的同事朋友聊天时,突然发现自己得到的东西却很少很少,于是想认真的 ...

  7. MongoDB之建立Windows和本地虚拟机的双向连接

    本文主要分享如何将MongoDB数据库在Windows系统和本地虚拟机系统建立双向连接,我们将借助MongoDB的可视化工具Robomongo来实现.首先,应该确保你的Windows系统和本地虚拟机系 ...

  8. 为PowerApps和Flow,Power BI开发自定义连接器

    作者:陈希章 发表于 2017年12月20日 前言 我在之前用了几篇文章来介绍新一代微软商业应用平台三剑客(PowerApps,Microsoft Flow,Power BI),相信对于大家会有一种跃 ...

  9. Android应用开发allowBackup敏感信息泄露的一点反思

    1 背景 [工匠若水 http://blog.csdn.net/yanbober 转载烦请注明出处.尊重劳动成果] 事实上这篇文章可能有些小题大作,但回过头想想还是非常有必要的,有点阴沟里翻船的感觉. ...

  10. JQuery学习(4-2-phpserver端1)

    主要内容:介绍图片的上传过程,涉及PHP跟JQuery: 1. 读取配置文件,连接MySQL数据库. 配置文件主要实username和password. 3-5.php <?php /* * v ...