本文为阅读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. jquery无new构建学习笔记

    当我们想要创建一个对象,我们可能使用new方法去构建一个对象,那按道理jquery也是一个对象,应该也是用new jquery()来构建呀为什么我们创建jquery对象不用new jquery()而是 ...

  2. js计时函数实现秒表的开始-暂停-清零功能

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. ES6模块化

    关于ES6模块化 历史上,JavaScript 一直没有模块(module)体系,无法将一个大程序拆分成互相依赖的小文件,再用简单的方法拼装起来.其他语言都有这项功能,比如 Ruby 的require ...

  4. SQL Server学习之路(一):建立数据库、建立表

    0.目录 1.前言 2.建立数据库 2.1 通过SSMS建立数据库 2.2 通过SQL语句建立数据库 3.建立表 3.1 通过SSMS建立表 3.2 通过SQL语句建立表 1.前言 配置是win10+ ...

  5. web前端素材整理汇总

    最近一直搞前端开发,整理下前端用的一些常用素材,分享给大家 框架类 Vue:https://cn.vuejs.org/ iview:https://www.iviewui.com/ 插件类 Jquer ...

  6. 【luogu P1186】玛丽卡

    https://www.luogu.org/problem/show?pid=1186 考虑暴力,枚举图上每一条边删去后跑Dijkstra,取M次的最大值. 仔细想想就会发现删除最短路以外的边对最短路 ...

  7. 基于百度地图SDK和Elasticsearch GEO查询的地理围栏分析系统(1)

    本文描述了一个系统,功能是评价和抽象地理围栏(Geo-fencing),以及监控和分析核心地理围栏中业务的表现. 技术栈:Spring-JQuery-百度地图WEB SDK 存储:Hive-Elast ...

  8. Java---Ajax在Struts2框架的应用实例

    Ajax 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. 很久没有动过ajax了,趁此机会复习一下,写一个简单的例子 一.项目结构: 二.需要的jar包 三.具体代码: 1.web.x ...

  9. 剑指offer面试题14-调整数组顺序使奇数位于偶数前面

    题目: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得全部奇数位于数组的前半部分.全部偶数位于数组的后半部分. 前后分的这个.,让我想起来高速排序.好吧,就用这个做. 考虑到了排序的可扩 ...

  10. MySQL 删除数据库中反复数据(以部分数据为准)

    delete from zqzrdp where tel  in (select min(dpxx_id) from  zqzrdp  group by tel  having count(tel)& ...