CSS后代选择器未对所有目标元素应用样式 [英] CSS descendant selector not applying styles to all targeted elements

查看:305
本文介绍了CSS后代选择器未对所有目标元素应用样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  body> p * {background-color:red;}  

 身体> < p>我见过很多< span>名人< / span>在我的一生。 < p>他们< / p>都是富人!我有一个列表< ul>< li> one< / li>< li> two< / li>< li> three< / li>< / ul>< / p&  



为什么,'名人'



根据我对后代选择器的理解,< span> < ul&在第一个< p> 内的< p>



如果我修改上述内容如下,它会工作,为什么?



  body> div * {background-color:red;}  

  div>我见过很多< span>名人< / span>在我的一生。 < p>他们< / p>都是富人!我有一个列表< ul>< li>一个< / li>< li>两个< / li>< li>三< / li>< / ul>< / div>  

解决方案

p标签不能嵌套在其他p标签。当它解析您的标记时,它在嵌套的p标记之前插入一个(缺少的)关闭p标签。

 < p&我见过很多< span>名人< / span>在我的一生。 < p> 
< 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>

这篇关于CSS后代选择器未对所有目标元素应用样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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