用于渲染新行的HTML规范?
我正在尝试将一些简单的
HTML文档(大部分包含div和br标签)呈现为纯文本,但是我正在努力添加新行.我认为这将是非常简单的< div>和< br />生成新行,但它似乎有各种微妙的规则.例如:
<div>one line</div> <div>two lines</div> <hr/> <div>one line</div> <div></div> <div>still two lines because the empty div doesn't count</div> <hr/> <div>one line<br/></div> <div></div> <div>still two lines because the br tag is ignored</div> <hr/> <div>one line<br/></div> <div><br/></div> <div>three lines this time because the second br tag is not ignored</div> <hr/> <div><div>Wrapped tags generate only one new line<br/></div></div> <div><br/></div> <div>three lines this time because the second br tag is not ignored</div> 所以我正在寻找一个关于如何在HTML文档中渲染新行的规范(当不应用CSS时).任何想法,我可以找到这种文件? 解决方法
如果您正在寻找< div>的规范和< br>
你不会在一个地方找到它,因为他们都遵循不同的规则. DIV元素遵循块格式规则,而BR元素遵循文本流规则. 我相信你的混乱的原因是他们遵循相同的新规则的假设. BR元素. BR在HTML4 Specification Section 9.3中定义关于行和段落:
并在HTML5 Specification Section 4.5年关于文本级语义:
规范说明了第三个例子: <div>one line<br/></div> <div></div> <div>still two lines because the br tag is ignored</div> 在那里,BR元素根本不被忽略,因为它标记该线必须在那一点被破坏. 在你的第四个例子中: <div>one line<br/></div> <div><br/></div> <div>three lines this time because the second br tag is not ignored</div> BR元素也标志着该行的结束. 因此,在第三和第四个例子中,规则是一样的. DIV元素. 在没有显式样式表的情况下,应用默认样式.
因此,这也不是创建新行,因为在块格式化的上下文中,没有线的概念. 在你的第二个例子中: <div>one line</div> <div></div> <div>still two lines because the empty div doesn't count</div> 空DIV具有零高度,因此它对下一个块级元素的呈现没有影响. 在你的第五个例子中: <div><div>Wrapped tags generate only one new line<br/></div></div> <div><br/></div> <div>three lines this time because the second br tag is not ignored</div> 外部DIV作为Section 9.1.2定义的包含块 我相信这就是一切. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |