是“div” p“ & “div p”相同? [英] Are "div > p" & "div p" same?

查看:142
本文介绍了是“div” p“ & “div p”相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我有一个明显的问题。



如下代码:

 code>< div> 
< p>我们要格式化此文字:)< / p>
< / div>

有些人使用选择器:

  div> p {
something
}

其他:

  div p {
something
}

在这种情况下有什么区别?在我看来 - 没有?



顺便说一句,不是子孙项目总是一个孩子吗?两者之间有什么区别?我正在阅读w3.org但不能得到它:)



谢谢!

方案

简单:

  div& p 

只会影响直接子女。

  div p 

会影响孙子

不受IE6支持


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 :)

Thank you!

解决方案

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.

这篇关于是“div” p“ &amp; “div p”相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆