What does the quot;~quot; (tilde/squiggle/twiddle) CSS selector mean?(“~是什么意思?(波浪线/波浪线/旋转) CSS 选择器是什么意思?)
问题描述
搜索 ~ 字符并不容易.我正在查看一些 CSS 并找到了这个
Searching for the ~ character isn't easy. I was looking over some CSS and found this
.check:checked ~ .content {
}
什么意思?
推荐答案
~ 选择器其实就是通用兄弟组合器(在 选择器级别 4):
The ~ selector is in fact the General sibling combinator (renamed to Subsequent-sibling combinator in selectors Level 4):
一般的兄弟组合子由波浪号"(U+007E,~)组成分隔两个简单选择器序列的字符.这由两个序列表示的元素在文档树和第一个序列表示的元素在(不一定立即)由第二个.
The general sibling combinator is made of the "tilde" (U+007E, ~) character that separates two sequences of simple selectors. The elements represented by the two sequences share the same parent in the document tree and the element represented by the first sequence precedes (not necessarily immediately) the element represented by the second one.
考虑以下示例:
.a ~ .b {
background-color: powderblue;
}
<ul>
<li class="b">1st</li>
<li class="a">2nd</li>
<li>3rd</li>
<li class="b">4th</li>
<li class="b">5th</li>
</ul>
.a ~ .b 匹配第 4 和第 5 个列表项,因为它们:
.a ~ .b matches the 4th and 5th list item because they:
- 是
.b元素 - 是
.a 的兄弟姐妹 - 在 HTML 源代码顺序中出现在
.a之后.
- Are
.belements - Are siblings of
.a - Appear after
.ain HTML source order.
同样,.check:checked ~ .content 匹配所有 .content 元素,它们是 .check:checked 的兄弟元素并出现在它之后.
Likewise, .check:checked ~ .content matches all .content elements that are siblings of .check:checked and appear after it.
这篇关于“~"是什么意思?(波浪线/波浪线/旋转) CSS 选择器是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“~"是什么意思?(波浪线/波浪线/旋转) CSS 选
基础教程推荐
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
