阅读MDN文档之CSS选择器介绍(一)
目录
Different types of Selectors
Simple selectors: Match one or more elements based on element type, class or id(还有通用选择器).
Attribute selectors: Match one or more elements based on their attributes/attribute values.
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.
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)
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.
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.
AB: Any element matching both A and B at the same time.
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.)
A > B: Any element matching B that is a direct child of an element matching A.
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.)
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选择器介绍(一)的更多相关文章
- 阅读MDN文档之StylingBoxes(五)
目录 BoxModelRecap Box properties Overflow Background clip Background origin Outline Advanced box prop ...
- 阅读MDN文档之布局(四)
Introducing positioning Static positioning Relative positioning Introducing top, bottom, left and ri ...
- 阅读MDN文档之基本盒模型(三)
Box properties Margin collapsing Adjacent siblings(相邻兄弟) Parent and first/last child Empty blocks Ac ...
- 阅读MDN文档之布局(四)
Introducing positioning Static positioning Relative positioning Introducing top, bottom, left and ri ...
- 阅读MDN文档之层叠与继承(二)
目录 The cascade Importance Specificity Source order A note on rule mixing Inheritance Controlling inh ...
- 前端开发必备之MDN文档
想下载MDN文档的看前面的内容就可以了. HTML 源码下载 MDN官方下载地址:https://developer.mozilla.org/media/developer.mozilla.org.t ...
- Winform开发框架中的内容及文档管理模块功能介绍
在开发项目的时候,我们有一些场景需要编辑一些HTML文档,作为内容发布系统的一部分,有时候也需要对一些文档如WORD文档进行编辑管理,这样需要我们对这些内容及文档进行合适的管理.本文主要介绍在WInf ...
- Emacs阅读chm文档
.title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium ...
- MDN 文档高级操作进阶教程
MDN 文档高级操作进阶教程 MDN 文档, 如何优雅的使用 MDN 文档上的富文本编辑器 pre & 语法高亮器 code & note box source code 上传附件 i ...
随机推荐
- Geth控制台使用及Web3.js使用实战
在开发以太坊去中心化应用,免不了和以太坊进行交互,那就离不开Web3. Geth 控制台(REPL)实现了所有的web3 API及Admin API, 使用好 Geth 就是必修课.结合Geth命令用 ...
- 导入Excel 文件(图片和文字)NPOI+BootStrap fileinput 插件 的结合使用
1.页面代码: <!DOCTYPE html><html><head> <meta name="viewport" content=&qu ...
- 天梯赛 L2-020. 功夫传人 BFS
L2-020. 功夫传人 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一门武功能否传承久远并被发扬光大,是要看缘分的.一般来 ...
- 两个实用linux小工具
使用 sshpass 工具来做名密码输入 使用 alias 别名来做成命令语句. Linux命令之非交互SSH密码验证-sshpass ssh登陆不能在命令行中指定密码.sshpass的出现,解决了这 ...
- javascript设计模式——职责链模式
前面的话 职责链模式的定义是使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系,将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止.职责链模式的名字非常形象,一 ...
- Codeforces 821E Okabe and El Psy Kongroo
题意:我们现在位于(0,0)处,目标是走到(K,0)处.每一次我们都可以从(x,y)走到(x+1,y-1)或者(x+1,y)或者(x+1,y+1)三个位子之一.现在一共有N段线段,每条线段都是平行于X ...
- 在centos7中手动编译greenplum
一.编译环境 Linux version 3.10.0-327.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.3 2014 ...
- handler 源代码分析
handler Looper 轮询器 MessageQueue 消息对象 1 主线程在一创建的时候就会调用, public static void prepareMainLooper() {}构造方法 ...
- opencv批处理提取图像的特征
____________________________________________________________________________________________________ ...
- Android学习笔记(27):日历视图Calendar
日历视图CalendarView可用于显示和选择日期. 能够调用setOnDateChangedListener()方法绑定事件监听器. 经常使用XML属性和相关方法: XML属性 相关方法 说明 a ...