如何在 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