<预>标签使浏览器关闭段落预>
我对下面的 HTML 有疑问:
<html>
<body>
<p style="font-size: large">
Some paragraph text
<span><pre style="display:inline">some span text</pre></span>
additional paragraph text that continues ...
</p>
</body>
</html>
所以这只是一个中间包含一些预格式化文本的段落。我遇到的问题是 Opera 和 Chrome 都没有按照我期望的方式显示。具体来说,他们关闭跨度之前的段落标签并强制换行。什么?!
使用 chromes HTML 检查选项,它显示
标记正在关闭,并插入了一个空的
,而不是封闭
><前>
。如果删除了跨度,chrome 仍然会关闭
标签,强制换行。
我需要显示以下标签结构,而不强制显示任何换行符
。这是否可能,或者还有其他选择或解决方法吗?
< /p>
编辑: 我被锁定为
标签,因为它是 WordPress 语法突出显示插件的一部分。
笔记: 我认为最好的建议是验证您的 HTML。我遇到的很多问题都是由于无效的 HTML 造成的,某些浏览器可以很好地处理这些无效的 HTML,而其他浏览器则不能很好地处理这些问题。验证意味着您可以从头开始工作。
I'm having an issue with the HTML below:
<html>
<body>
<p style="font-size: large">
Some paragraph text
<span><pre style="display:inline">some span text</pre></span>
additional paragraph text that continues ...
</p>
</body>
</html>
So this is just a paragraph that contains some preformatted text in the middle. The problem that I am having is that both Opera and Chrome don't display this the way I expect. Specifically they close the paragraph tag before the span and force a new line. WTH?!
Using chromes HTML inspection options it shows that the <p>
tag is being closed and an empty <span></span>
inserted instead of enclosing the <pre>
. If the span is removed chrome still closes the <p>
tag, forcing a newline.
I need to have the following tag structure display without any newlines being forced <p><span><pre><code></code></pre></span></p>
. Is this at all possible or is there another option or workaround?
EDIT:
I'm locked into having the <pre>
tag as it is part of a syntax highlighting plugin for wordpress.
NOTE:
I think the best piece of advice here is to validate your HTML. A lot of the problems I was having was because of invalid HTML that was being handled gracefully by some browsers and not gracefully by others. Validating means you have a clean slate to work from.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
完全去掉
pre
标签,只给你的span
style="white-space:pre"
。有关其他空白此页面 > 选项。
Get rid of the
pre
tag altogether, and just give yourspan
style="white-space:pre"
. See this page for a description of otherwhite-space
options.<pre>
is basically saying<div style="white-space:pre">
; what you want is<span style="white-space:pre">
.段落标签不能包含块级元素:
http:// www.w3.org/TR/html401/struct/text.html#h-9.3.1
pre
是块级元素。如果您希望在内联元素中具有类似
pre
的行为,您可以在 Span 上设置 CSS 样式white-space: pre
。Paragraph tags cannot contain block-level elements:
http://www.w3.org/TR/html401/struct/text.html#h-9.3.1
pre
is a block level element.You could instead set the CSS style
white-space: pre
on your span if you desired to havepre
-like behavior in an inline element.pre
是一个块级元素,如果内存正常,则不允许它位于span
内。您可以通过验证 HTML 来找出答案。
pre
is a block level element, it isn't allowed to be inside aspan
if memory serves right.You can find out by validating your HTML.