html基本标签

标题标签

任何文档都以标题开头。 您可以为标题使用不同的大小。 HTML还有六个标题级别,使用元素<h1>, <h2>, <h3>, <h4>, <h5>, and <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>

这将产生以下结果 −

This is heading 1

This is heading 2

This is heading 3

This is heading 4

This is heading 5

This is heading 6

段标记

<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>

这将产生以下结果 −

Here is a first paragraph of text.

Here is a second paragraph of text.

Here is a third paragraph of text.

换行标记

无论何时使用<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>

这将产生以下结果 −

Hello
You delivered your assignment on time.
Thanks
Mahnaz

放置内容到中心

您可以使用 <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>

这将产生以下结果 −

This text is not in the center.

This text is in the center.

水平线

水平线用于在视觉上分解文档的各个部分。  <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>

这将产生以下结果 −

This is paragraph one and should be on top


This is paragraph two and should be at bottom

再次<hr />标记是空元素的一个示例,您不需要打开和关闭标记,因为它们之间没有任何内容。

<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>

这将产生以下结果 −

 
function testFunction( strText ){ 
   alert (strText) 
} 

尝试使用相同的代码而不将其保留在<pre> ... </pre>标记内。

不间断空格

假设您要使用短语“12 Angry Men”。 在这里,你不希望浏览器将“12 Angry”和“Men”分成两行 −

An example of this technique appears in the movie "12 Angry Men."

如果您不希望客户端浏览器中断文本,则应使用不间断空格  而不是正常的空间。 例如,在段落中对“12 Angry Men”进行编码时,您应该使用类似于以下代码的内容 −

例子

<!DOCTYPE html>
<html>

   <head>
      <title>Nonbreaking Spaces Example</title>
   </head>
	
   <body>
      <p>An example of this technique appears in the movie "12&nbsp;Angry&nbsp;Men."</p>
   </body>
	
</html>

这将产生以下结果 −

An example of this technique appears in the movie "12 Angry Men."

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值