任何文档都以标题开头.您可以为标题使用不同的尺寸. HTML还有六个级别的标题,使用元素< h1>,< h2>,< h3>,< h4>,< h5>,和 <h6> 的.在显示任何标题时,浏览器会在该标题之前添加一行,在该标题之后添加一行.
<!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>标记之间,如下例所示:
<!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 />元素时,其后的所有内容将从下一行开始。 此标记是一个空元素的示例,您无需打开和关闭标记,因为它们之间没有任何内容。
<br />标记在字符br和正斜杠之间有一个空格。 如果省略此空间,则较旧的浏览器将无法显示换行符,而如果您错过了正斜杠字符而仅使用<br>,则在XHTML中无效。
<!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>标记将任何内容置于页面或任何表格单元格的中心。
<!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>标记在文档的当前位置到右页边距之间创建一行,并相应地断开该行。
例如,您可能希望在两个段落之间加上一行,如下面的示例所示:
<!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>标记之间的任何文本都将保留源文档的格式。
<!DOCTYPE html> <html> <head> <title>Preserve Formatting Example</title> </head> <body> <pre> function testFunction( strText ){ alert (strText) } </pre> </body> </html>
尝试使用相同的代码而不将其保留在<pre> ... </ pre>标记内
假设您要使用短语" 12个愤怒的男人"。 在这里,您不希望浏览器将" 12,Angry"和" Men"分成两行:
An example of this technique appears in the movie "12 Angry Men."
在某些情况下,如果您不希望客户端浏览器破坏文本,则应使用不间断的空格实体; 而不是正常的空间。 例如,当对一个段落中的" 12个愤怒的人"进行编码时,应使用类似于以下代码的内容:
<!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>