html - <pre> 标签使浏览器关闭段落

标签 html css google-chrome opera

我遇到以下 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 都没有按照我期望的方式显示。具体来说,他们在跨度之前关闭段落标记并强制换行。什么?!

使用 chrome HTML 检查选项显示 <p>标签正在关闭且为空 <span></span>插入而不是包含 <pre> .如果删除跨度,chrome 仍会关闭 <p>标记,强制换行。

我需要在不强制换行的情况下显示以下标签结构 <p><span><pre><code></code></pre></span></p> .这完全可能还是有其他选择或解决方法?

编辑: 我被锁定了 <pre>标记,因为它是 wordpress 语法高亮插件的一部分。

注意: 我认为这里最好的建议是验证您的 HTML。我遇到的很多问题都是因为无效的 HTML 被一些浏览器优雅地处理,而其他浏览器却没有优雅地处理。验证意味着您可以从头开始工作。

最佳答案

去掉 pre完全标记,然后给出你的 span style="white-space:pre" .参见 this page其他的描述white-space选项。

<pre>基本上是说 <div style="white-space:pre"> ;你要的是<span style="white-space:pre"> .

关于html - <pre> 标签使浏览器关闭段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3508415/

相关文章:

html - Bootstrap Glyphicons 在数据切换折叠时旋转

CSS3 : two transitions with different timing functions (css3)

javascript - 在本地主机上唯一识别客户端

css - Google Web 字体无法在 Windows 7 上的 Chrome 中正确显示

html - 细字体在 Windows 上无法正确显示

html - CSS 中的复杂边界半径问题(不同的边曲线到 Angular 曲线)

html - 当我扩展浏览器宽度时,CSS div 向下移动

jquery - 根据 th 的类隐藏 td 元素

javascript - 如何遍历输入中输入的数组并根据其类型进行分类?

css - 为什么 grunt-contrib-less 找不到 Bootstrap 变量?