博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
css后代选择器与子选择器_后代选择器(CSS选择器)
阅读量:2508 次
发布时间:2019-05-11

本文共 2195 字,大约阅读时间需要 7 分钟。

css后代选择器与子选择器

描述 (Description)

The descendant selector matches all elements that are descendants of a specified element. The first simple selector within this selector represents the ancestor element—a structurally superior element, such as a parent element, or the parent of a parent element, and so on. The second simple selector represents the descendant element we’re trying to match.

后代选择器匹配作为指定元素的后代的所有元素。 该选择器中的第一个简单选择器代表祖先元素 -结构上较高的元素,例如父元素或父元素的父元素,依此类推。 第二个简单的选择器代表我们要匹配的后代元素。

The combinator we use in a descendant selector is a whitespace character: a space, horizontal tab, carriage return, line feed, or form feed. Since whitespace characters are allowed around all combinators, you can include more than one whitespace character between the simple selectors in a descendant selector.

我们在后代选择器中使用的组合器是一个空白字符:空格,水平制表符,回车,换行或换页。 由于所有组合器周围都允许使用空格字符,因此您可以在子代选择器的简单选择器之间包含多个空格字符。

Consider the following HTML fragment:

考虑以下HTML片段:

  • Item 1
    1. Sub-item 2A
    2. Sub-item 2B

We’ll try to match elements in the above fragment using the selector below:

我们将尝试使用以下选择器匹配上述片段中的元素:

ul li {  ⋮ declarations}

This descendant selector will match all four li elements in the example HTML, because each of those elements has a ul element as its ancestor.

此后代选择器将匹配示例HTML中的所有四个li元素,因为这些元素中的每一个都有一个ul元素作为其祖先。

We can also use descendant selectors to match the li elements within the ol in the example above:

在上面的示例中,我们还可以使用后代选择器来匹配ol中的li元素:

ul * li {  ⋮ declarations}ul * * li {  ⋮ declarations}ul * ol li {  ⋮ declarations}ul li * li {  ⋮ declarations}ul ol li {  ⋮ declarations}ul li li {  ⋮ declarations}ul li ol li {  ⋮ declarations}

However, there’s no way we can use descendant selectors to match only the list items in the unordered list. To do that, we’d need a child selector.

但是,我们无法使用后代选择器仅匹配无序列表中的列表项。 为此,我们需要一个子选择器。

(Example)

Take a look at this example of the descendant selector in action:

看一下实际的后代选择器的示例:

ul li {  ⋮ declarations}

This selector matches all li elements that are descendants of a ul element—that is, every li element that has a ul element as its ancestor.

该选择器匹配作为ul元素后代的所有li元素,即,每个以ul元素为祖先的li元素。

翻译自:

css后代选择器与子选择器

转载地址:http://tbrgb.baihongyu.com/

你可能感兴趣的文章
百元买百鸡问题 ---穷举法
查看>>
[转]为什么不去读顶级会议上的论文
查看>>
Android模拟按键——源码环境下开发应用程序 ---编译jar(android可执行程序)
查看>>
Android Bluetooth HID实现详解
查看>>
Android AudioRecord Demo[录音并且声称PCM文件]
查看>>
设计模式之---代理模式
查看>>
解决SpringMVC重复提交的问题
查看>>
使用SSH命令行远程登录运行在CloudFoundry上的应用
查看>>
Telnet实现windows远程登录ubuntu
查看>>
Jenkins安装
查看>>
java面试题之osi七层网络模型,五层网络模型,每层分别有哪些协议(阿里面试题)...
查看>>
计算机名词、论文用语
查看>>
RESTful-rest_framework认证组件、权限组件、频率组件-第五篇
查看>>
手机自带功能调用
查看>>
百度搜索引擎取真实地址-python代码
查看>>
java 多线程 Future callable
查看>>
字符串操作练习:星座、凯撒密码、99乘法表
查看>>
Java实现字符串转换十六进制MD5值
查看>>
MySQL数据库8(十七)数据库的备份还原
查看>>
tensorflow 梯度下降以及summary
查看>>