<分区>
最近几天我一直在阅读有关 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/