简体   繁体   English

范围内的标签p不适用于CSS样式

[英]Tag p inside a span doesn't apply css style

I'm having an issue with styles. 我的样式有问题。 My code is something like this: 我的代码是这样的:

 .grey { color:grey; } 
 <span class="grey"> <p align="justify"><b>Text</b></p> </span> <span class="grey"> Text 2 </span> 

"Text" appears black, while "Text 2" appears grey. “文本”显示为黑色,而“文本2”显示为灰色。 I've tried using a div instead of span, but doesn't work. 我尝试使用div而不是span,但是不起作用。 (I've read that span -> p isn't allowed) (我读过跨度-> p不允许)

PS: (It works locally with Firefox, but when I'm checking it on the iPad (this is for an iPad app), it doesn't). PS :(它在Firefox上本地工作,但是当我在iPad上检查它(适用于iPad应用程序)时,它不能运行)。

Is there a way to force p to apply the style of the span?. 有没有一种方法可以强制p应用跨度样式?

<span> is inline level element, it cannot be placed around a <p> element because Paragraphs <p> is block level element. <span>内联级别元素,不能将其放置在<p>元素周围,因为段落<p>块级别元素。 The rule is that block level elements can contain any number of inline or block elements. 规则是级元素可以包含任意数量的内联或块元素。 Inline level elements can only contain inline elements. 内联级别元素只能包含内联元素。

Your HTML should be the following and it'll work: http://jsfiddle.net/amyamy86/RENbN/ 您的HTML应该如下,并且可以正常工作: http : //jsfiddle.net/amyamy86/RENbN/

<div class="grey">
   <p align="justify"><b>Text</b></p>
</div>

<span class="grey">
  Text 2
</span>

For more information regarding inline and block elements see: 有关内联元素的更多信息,请参见:

If you are still seeing "Text" in black is mostly because there is some CSS selector that has higher specificity and is overriding your .grey selector. 如果仍然看到黑色的“文本”,则主要是因为有一些CSS选择器具有更高的特异性,并且覆盖了.grey选择器。

Another walkaround I found that works ( best solution is to change span for div) , add in CSS: 我发现另一个可行的解决方法(最好的解决方案是更改div的跨度),在CSS中添加:

.grey p 
 {
    color: gray;
 }

This will work too. 这也将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM