css - css中后续兄弟组合符(~)和子选择符(>)的区别

标签 css css-selectors

<分区>

最近几天我一直在阅读有关 CSS 的内容,并在互联网上搜索了这个问题。

谁能解释一下 (~) 和 (>) 之间的区别是什么?

最佳答案

一般兄弟意味着元素在另一个元素之后,其中子选择器的目标元素是直接在某些元素内。

sibling :

HTML:

<div class="brother"></div>
<div class="sister"></div>

CSS:

.brother ~ .sister {
    /* This styles .sister elements that follow .brother elements */
}

children :

HTML

<div class="parent">
    <div class="child">
        <div class="child"></div>
    </div>
</div>

CSS:

.parent > .child{
    /* This styles .child element that is the direct child of the parent element;
    It will not style the .child element that is the child of .child */
}

关于css - css中后续兄弟组合符(~)和子选择符(>)的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22868288/

相关文章:

javascript - 如何降低条形高度 - Chart.js

CSS 选择器以匹配同一类的所有其他元素,除了选定的一个 ("This")

html - CSS last-child 选择器不工作

html - 伪类 :current

html - 停止自动换行

html - 如何在 div 中对齐 Accordion 居中

html - 左列固定宽度,右列高度;右列流体宽度

html - 将导航栏保持在图像 slider 上方 wordpress 主题

css - 单选按钮选择器 CSS ONLY pls

JQuery:包含一些文本但不包含其他文本的选择器