段落忽略样式,因为另一个嵌套段落 [英] Paragraph ignores style because of another nested paragraph

查看:155
本文介绍了段落忽略样式,因为另一个嵌套段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能我的CSS知识有限,但我不知道这个:

 < p style =绿色> 
< p style =color:red>这是红色< / p>
这应该是绿色的。但它不是。
< / p>

第二行将以黑色呈现,忽略color:green。为什么?
我在Chrome 28和Firefox 22中测试过。

解决方案



Paragraph是一个自动关闭元素,< / p> 是可选的 - 任何块元素将自动关闭最后一次打开< p>



这是发生了什么: b
$ b

 < p style =color:green> 
< / p> <! - 自动关闭段落 - >

< p style =color:red>
这是红色
< / p>

这应该是绿色的。但它不是。

< / p> <! - 这里你有语法错误 - >


Probably my CSS knowledge is limited, but I don't uderstand this:

<p style="color: green">
    <p style="color: red">This is red</p>
    This should be green. But it's not.
</p>

The second line will render in black ignoring the "color:green". Why? I tested it in Chrome 28 and Firefox 22.

解决方案

You can't nest paragraphs.

Paragraph is an auto-closing element, the </p> is optional - any block element will automatically close the last open <p>.

This is what's happening:

<p style="color: green">
</p> <!-- auto-closed paragraph -->

<p style="color: red">
    This is red
</p>

This should be green. But it's not.

</p> <!-- here you have syntax error -->

这篇关于段落忽略样式,因为另一个嵌套段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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