为什么此选择器不应用于给定的标记? [英] Why is this selector not being applied to the given tag?

查看:127
本文介绍了为什么此选择器不应用于给定的标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此选择器无法像我预期的那样工作:

 < style type =text / css> 
.someClass p,b {
color:red;
cursor:pointer;
}
< / style>
< p>这是一个测试< / p>
< p>这是另一个< b>测试< / b>< / p>
< p class =someClass>这是一个使用someClass< / p>
< p>这是另一个< b class =someClass>测试< / b>< / p>

结果和 jsFiddle
非风格的段落和样式的文本显示为黑色。
使用someClass类型的 p 的文本不会以红色文本显示,但 b 类someClass出现红色。



问题:
为什么 p class =someClass (第三段)不会显示为红色,而 b class =someClass红?



这两个标签都包含在someClass选择器中。我没有太多运气在通过搜索找到答案,而文档似乎不能解决这一确切的情况。

解决方案

如果您希望将样式应用于段落, c $ c> b 元素 someClass ,使用

 code> p.someClass,b.someClass {
color:red;
cursor:pointer;
}

您现有的选择器定位




  • 任何 b 元素

  • c> someClass 。



此代码:

  .someClass p,b {something} 

  .someClass p {something} 
b {something}


This selector isn't working like I might expect:

<style type="text/css">
    .someClass p, b {
        color:red;
        cursor : pointer;
    } 
</style>
<p>This is a test</p>
<p>This is another <b>test</b></p>
<p class="someClass">This is a test with someClass</p>
<p>This is another <b class="someClass">test</b></p>

Results and jsFiddle: Text for the non-styled paragraphs and styles appear black. Text for the p with class "someClass" is not appearing with red text, however the b with class "someClass" does appear red.

Problem: Why does the p class="someClass" (third paragraph) not appear in red, while the b class="someClass" (fourth paragraph) appears in red?

Both tags are included in the someClass selector. I've not had much luck in finding an answer with searching, and the documentation doesn't appear to address this exact scenario

解决方案

If you want your style to apply to paragraphs and b elements with class someClass, use

p.someClass, b.someClass {
    color: red;
    cursor: pointer;
}

Your existing selector targets

  • any b element
  • paragraphs that are inside an element having the class someClass.

This code :

.someClass p, b { something }

is the same as

.someClass p { something }
b { something }

这篇关于为什么此选择器不应用于给定的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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