HTML - <nobr> 标签



HTML <nobr> 标签用于指示浏览器不要换行指定的文本(例如浏览器窗口右侧边缘处通常发生的换行)。

它与 <wbr> 标签一起使用,<wbr> 建议扩展浏览器何时可以在原本不可换行的文本序列中插入换行符。与 <br> 标签不同,<br> 标签始终导致换行,即使在 <nobr> 标记的段落内也是如此,<wbr> 标签仅在放置在 <nobr> 标记的内容段落内时才有效,并且仅在当前行已扩展到浏览器的显示窗口边距之外时才会导致换行。

此标签不再推荐,因为它已弃用并且在 HTML5 中不受支持。您可以改用 CSS 属性。

语法

<nobr> Statement </nobr>

属性

HTML nobr 标签支持 HTML 的全局属性。

HTML nobr 标签示例

以下示例将说明 nobr 标签的用法。在何处、何时以及如何使用 nobr 标签来继续句子。

不换行语句

考虑以下示例,我们将对句子使用 <nobr> 标签。

<!DOCTYPE html>
<html>

   <head>
      <title>HTML nobr Tag</title>
   </head>

   <body>
      <h3>Normal Paragraph</h3>
      <p>
         This is a very long sequence of text that
         is forced to be on a single line, even if 
         doing so causes the browser 
         to extend the document window beyond the 
         size of the viewing pane and the poor user 
         must scroll right to read the
         entire line.
      </p>
      <h3>No Break Paragraph</h3>
      <nobr>
         This is a very long sequence of text that
         is forced to be on a single line, even if 
         doing so causes the browser 
         to extend the document window beyond the 
         size of the viewing pane and the poor user 
         must scroll right to read the
         entire line.
      </nobr>
   </body>

</html>

块引用内的不换行语句

众所周知,blockquote 元素会包裹文本,并且在出现不可换行句子时不允许滚动,它会强制换行,但使用 nobr 标签后,它不会产生影响。

<!DOCTYPE html>
<html>

   <head>
      <title>HTML nobr Tag</title>
      <style>
      blockquote {
          width: 200px;
      }
      </style>
   </head>

   <body>
      <h3>No Break Paragpagh with Blockquote</h3>
      <blockquote>
      <nobr>
         This is a very long sequence of text that
         is forced to be on a single line, even if 
         doing so causes the browser 
         to extend the document window beyond the 
         size of the viewing pane and the poor user 
         must scroll right to read the
         entire line.
      </nobr>
      </blockquote>
      <blockquote>
         This is a very long sequence of text that
         is forced to be on a single line, even if 
         doing so causes the browser 
         to extend the document window beyond the 
         size of the viewing pane and the poor user 
         must scroll right to read the
         entire line.
      </blockquote>
   </body>

</html>

支持的浏览器

标签 Chrome Edge Firefox Safari Opera
nobr 是 1.0 是 12.0 是 1.0 是 4.0 是 15.0
html_tags_reference.htm
广告