基本标签
标题标签
任何文档都以标题开头。 您可以为标题使用不同的大小。 HTML还有六个级别的标题,使用元素《h1》, 《h2》, 《h3》, 《h4》, 《h5》,和《h6》 。 在显示任何标题时,浏览器在该标题之前添加一行,在该标题之后添加一行。
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
段标记
《p》标签提供了一种将文本结构化为不同段落的方法。 文本的每一段应介于开头“p”和结束“/ p”标签之间,如下例所示 -
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<p>Here is a first paragraph of text.</p>
<p>Here is a second paragraph of text.</p>
<p>Here is a third paragraph of text.</p>
</body>
</html>
换行标记
无论何时使用《br /》元素,其后面的任何内容都从下一行开始。 此标记是一个empty元素的示例,您不需要打开和关闭标记,因为它们之间没有任何内容。
该
tag在字符br和正斜杠之间有一个空格。 如果省略此空格,旧浏览器将无法呈现换行符,而如果您错过了正斜杠字符并且只使用“br”,则它在XHTML中无效。
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br />
You delivered your assignment ontime.<br />
Thanks<br />
Mahnaz</p>
</body>
</html>
集中内容
您可以使用《center》标签将任何内容放在页面中心或任何表格单元格中。
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Centring Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
<center>
<p>This text is in the center.</p>
</center>
</body>
</html>
水平线
水平线用于在视觉上分解文档的各个部分。 《hr》标签创建从文档中的当前位置到右边距的线,并相应地断开线。
例如,您可能希望在两个段落之间给出一条线,如下面给出的示例所示 -
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr />
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
同样, 《hr /》标签是empty元素的一个示例,您不需要打开和关闭标记,因为它们之间没有任何内容。
《hr /》元素在字符hr和正斜杠之间有一个空格。 如果省略此空格,旧浏览器将无法呈现水平线,而如果您错过正斜杠字符并只使用《hr》 ,则它在XHTML中无效
保留格式
有时,您希望文本遵循HTML文档中的文本格式。 在这些情况下,您可以使用预格式化的标签《pre》 。
打开《pre》标记和结束《/pre》标记之间的任何文本都将保留源文档的格式。
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Preserve Formatting Example</title>
</head>
<body>
<pre>
function testFunction( strText ){
alert (strText)
}
</pre>
</body>
</html>
尝试使用相同的代码而不将其保留在《pre》...《/pre》标签内
不间断的空间
假设您要使用短语“12 Angry Men”。 在这里,你不希望浏览器将“12,愤怒”和“男人”分成两行 -
An example of this technique appears in the movie "12 Angry Men."
如果您不希望客户端浏览器中断文本,则应使用不间断的空间实体 而不是正常的空间。 例如,在段落中对“12愤怒的男人”进行编码时,您应该使用类似于以下代码的内容 -
例子 (Example)
<!DOCTYPE html>
<html>
<head>
<title>Nonbreaking Spaces Example</title>
</head>
<body>
<p>An example of this technique appears in the movie "12 Angry Men."</p>
</body>
</html>