选择器不会将样式应用于段落< p>的后代元件 [英] Selector not applying styles to descendants of paragraph <p> element
本文介绍了选择器不会将样式应用于段落< p>的后代元件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我做以下事情时,只有'Celebrities'这个词变成了红色。
data-hide =falsedata-console =truedata-babel =false> body> p $ {background-color:red;}
<体> < p>我遇到了许多< span> Celebrities< / span>在我的一生中。 < p为H.他们< / p为H.都很有钱!我有一个列表< ul> <李 - 酮< /锂> <李>二< /锂> <李>三< /锂> < / UL> < / body>
'Celebrities',唯一的红色?
从我对后裔选择符的理解中可以看出< span>
< ul>
和< p>
在第一个< p> code>应该是红色的,对吧?
如果我修改上面的内容,它为什么会起作用?为什么?
body> div * {background-color:red;}
< div>我遇到过很多< span>名流< / span>在我的一生中。 < p为H.他们< / p为H.都很有钱!我有一个列表< ul> <李 - 酮< /锂> <李>二< /锂> <李>三< /锂> < / div>< / div>
解决方案
p标签不能嵌套在其他p标签内。当它解析你的标记时,它会在嵌套的p标记之前插入一个(缺失)关闭p标记。
< p>我见过很多< span>名流< / span>在我的一生中。 < p为H.
< p>他们< / 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?
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 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屋!
查看全文