“div > p”和“div p”是一样的吗?
16lz
2021-01-22
Hey, I've an obvious question.
我有一个明显的问题。
For code like:
代码:
<div>
<p>We want to format this text :)</p>
</div>
Some people use selector like:
一些人使用选择器:
div > p {
something
}
And others:
及其他:
div p {
something
}
What's the difference in this case? In my opinion - none?
这种情况有什么不同?在我看来——没有?
And by the way, isn't the descendant item always a child?! What's the difference between the two? I'm reading w3.org but can't get it :)
顺便问一下,后代的东西是不是永远都是孩子?这两者之间有什么区别?我正在读w3。org,但却无法得到:)
Thank you!
谢谢你!
2 个解决方案
#1
28
Simple:
简单:
div > p
affects only direct children.
只影响直接的孩子。
div p
affects grandchildren, grandgrandchildren etc. as well. (Won't make a difference in your example)
影响孙辈、孙辈等。(在你的例子中不会有什么不同)
The child selector isn't supported by IE6.
该子选择器不受IE6的支持。