段落

来源:互联网 发布:java常见的开发框架 编辑:程序博客网 时间:2024/04/28 06:37

段落是用<p>标签定义的。

<p>This is another paragraph</p> 
HTML自动在一个段落前后各添加一个空行。
换行
当需要结束一行,并且不想开始新段落时,使用<br>标签。<br>标签不管放在什么位置,都能够强制换行。

<p>This<br>is a para<br>graph with line breaks</p> 

<br>标签是一个空标签,它没有结束标记。

注释
注释标签用来在HTML源文件中插入注释。注释会被浏览器忽略。你可以使用注释来解释你的代码,这可以在你以后编辑代码的时候帮助你。

<!-- This is a comment --> 

注意:你需要在左括号“<”后面跟一个感叹号,右括号不用。

技巧
当你写下HTML文本的时候,你不能确知在另外一个浏览器中,这些文本将被如何显示。有人用着大的显示器,有的人用的小一些。每次用户调整窗口大小的时候,文本都将被重新格式化。不要想在编辑器中写一些空行和空格来协助排版。
HTML将截掉你文本中的多余空格。不管多少个空格,处理起来只当一个。一点附加信息:在HTML里面,一个空行也只被当作一个空格来处理。
使用空段落<p>来插入空白行是一个坏习惯,请使用<br>标签来替代。(但是不要用<br>标签来创建列表,我们后面会专门学习HTML列表的。)
你也许注意到了段落可以不写结束标记</p>。别依赖它,HTML的下一个版本将不准你漏掉任何一个结束标签。
HTML自动在某些元素前后增加额外的空行,就像在段落和标题元素的前后一样。
我们使用了水平线(<hr>标签)来分隔我们教程的章节。

例如:
多个段落

<html><body><p>This paragraph contains a lot of lines in the source code, but thebrowser ignores it.</p><p>This paragraph contains a lot of spaces in the source code, but thebrowser ignores it.</p><p>The number of lines in a paragraph depends on the size of yourbrowser window. If you resize the browser window, the number of linesin this paragraph will change.</p></body></html>

这个例子说明了段落的一些默认行为。
换行

<html><body><p>To break<br>lines<br>in a<br>paragraph,<br>use the br tag.</p></body></html>

这个例子说明了在HTML文档中换行的使用。
格式

<html><body><p>My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnielies over the ocean. Oh, bring back my Bonnie to me.</p><p>Note that your browser simply ignores your formatting!</p></body></html>

这个例子说明了HTML显示格式的一些问题。
标题元素

<html><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><p>Use heading tags only for headings. Don't use them just to makesomething bold. Use other tags for that.</p></body></html>

这个例子说明了在HTML中显示标题元素的标签。
居中的标题元素

<html><body><h1 align="center">This is heading 1</h1><p>The heading above is aligned to the center of this page. The headingabove is aligned to the center of this page. The heading above isaligned to the center of this page.</p></body></html>

这个例子显示了一个居中的标题元素。

水平线

<html><body><p>The hr tag defines a horizontal rule:</p><hr><p>This is a paragraph</p><hr><p>This is a paragraph</p><hr><p>This is a paragraph</p></body></html>

这个例子说明了如何插入水平线。
隐藏的注释

<html><body><!--This comment will not be displayed--><p>This is a regular paragraph</p></body></html>

这个例子说明了在HTML文档中如何插入隐藏的注释。

背景色

<html><body bgcolor="yellow"><h2>Look: Colored Background!</h2></body></html>

这个例子说明了如何给页面设置背景色。


原创粉丝点击