定位< p>段的后代元素 [英] Targeting descendants of paragraph <p> elements
本文介绍了定位< p>段的后代元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行以下操作时,只有名人"一词会变成红色.
When I do the following only the word, 'Celebrities', gets a red color.
body > p * {
background-color: red;
}
<body>
<p>I have met many <span>Celebrities</span> in my lifetime.
<p>They</p> all were rich! I have a list
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</p>
</body>
为什么名人"是唯一的红色?
Why is, 'Celebrities', the only thing in red?
根据我对后代选择器的理解,第一个<p>
中的<span>
,<ul>
和<p>
应该是红色的,对吗?
From my understanding of descendant selectors the <span>
, <ul>
and <p>
inside the first <p>
should be red, right?
如果我按照以下方式修改上面的内容,那么为什么呢?
If I modify the above as follows it works, why?
body > div * {
background-color: red;
}
<div>I have met many <span>Celebrities</span> in my lifetime.
<p>They</p> all were rich! I have a list
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</div>
推荐答案
p标签不能嵌套在其他p标签内.当解析您的标记时,它会在嵌套的p标签之前插入一个(丢失的)关闭p标签.
p tags cannot be nested inside other p tags. When it parses your markup, it is inserting a (missing) closing p tag before the nested p tag.
<p>I have met many <span>Celebrities</span> in my lifetime. <p>
<p>They</p>
这篇关于定位< p>段的后代元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文