如何在 HTML 中禁止文字換行?
為了在 HTML 中禁止文字換行,我們將使用<nobr>標籤來建立單行文字,它不考慮語句的長度。如果我們想閱讀整個文字,則必須使用水平捲軸。它與<br>換行標籤正好相反。<nobr>標籤在 HTML5 中不受支援。此標籤不包含任何屬性,它具有開始和結束標籤。
HTML 中的 <nobr> 標籤
HTML <nobr> 標籤用於指示瀏覽器不要換行指定的文字。它與 <wbr> 標籤一起使用,<wbr> 建議擴充套件瀏覽器何時可以在原本不可換行的文字序列中插入換行符。
與 <br> 標籤不同,<br> 標籤始終導致換行,即使在 <nobr> 標籤的段落內也是如此,<wbr> 標籤僅在放置在 <nobr> 標籤的內容段落內時才有效,並且僅噹噹前行已超出瀏覽器的顯示視窗邊距時才會導致換行。
語法
以下是 HTML 中<nobr>標籤的語法:
<nobr> Statement </nobr>
示例
以下示例演示了 HTML 中<nobr>標籤的使用:
<!Doctype html>
<html>
<head>
<title>nobr Tag in HTML</title>
<style>
h1 {
color: blue;
}
</style>
</head>
<body>
<center>
<h1>TutorialsPoint</h1>
<h4>HTML nobr tag</h4>
<nobr> Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-technical subjects. </nobr>
</center>
</body>
</html>
示例
以下是 HTML 中<nobr>標籤的另一個示例:
<!DOCTYPE html> <html> <head> <title>HTML nobr Tag</title> </head> <body> <nobr>This is a very long sequence of text that is forced to be on a single line, even if doing so causes <wbr /> the browser to extend the document window beyond the size of the viewing pane and the poor user must scroll right <wbr /> to read the entire line. </nobr> </body> </html>
示例
在以下示例中,我們嘗試限制封閉文字中的換行符:
<!DOCTYPE html>
<html>
<head>
<title>nobr Tag Demonstration</title>
<style>
p.a {
white-space: nowrap;
}
</style>
</head>
<body>
<h1>Using CSS property white-space</h1>
<p class="a"> It is a very long text which is very inconvenient to read, as it is written in one line, and you have to scroll horizontally to read it. </p>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP