标题:HTML标签p和div的不同

原文:What is the difference between <p> and <div>?

链接:http://stackoverflow.com/questions/2226562/what-is-the-difference-between-p-and-div

作者:Andrew Hare

译者:MilkCu(http://blog.csdn.net/milkcu)

引言

在用CSDN博客的网页编辑器xhEditor写文章的时候,发现回车键由原来的生成<p>标签变为<div>标签了。对于<p>、<span>、<div>各标签的区别我还是明白的,但为什么编辑器会用这种变化呢。在我看来,这样在从其它地方粘贴内容的时候更容易保留样式吧,因为<div>比<p>支持的样式更多。在搜索资料的时候,发现Stack Overflow的一则问答不错的,分享一下。

译文

它们有语义上的不同,<div>标签用来作数据的容器,而<p>标签用来描述内容段落。

语义的不同让所有不同。HTML是一种标记语言,这意味着它要用有意义的方式来标记内容。大多数的开发者认为,语法是被动的,浏览器作用于这些标记,但是事实不是这样。

你选择的标记标签应能描述你的内容。不要在考虑外观的基础上标记你的文档,而是在它是什么的基础上标记你的文档。

如果你标记容器,就用<div>。如果你需要描述你的文章段落,就用<p>。

注意:理解<div>和<p>都是块状元素很重要,这意味着,大多数浏览器都会以相似的形式对待它们。

原文

They havesemanticdifference - a<div>element is designed to describe a container of data whereas a<p>element is designed to describe a paragraph of content.

The semantics make all the difference. HTML is a markup language which means that it is designed to "mark up" content in a way that is meaningful to the consumer of the markup. Most developers believe that the semantics of the document are the default styles and rendering that browsers apply to these elements but that is not the case.

The elements that you choose to mark up your content shoulddescribethe content.Don't mark up your document based on how it should look - mark it up based on what it is.

If you need a generic container purely for layout purposes then use a<div>. If you need an element to describe a paragraph of content then use a<p>.

Note:It is important to understand that both<div>and<p>areblock-level elementswhich means that most browsers will treat them in a similar fashion.

更多相关文章

  1. struts2和struts1.x的标签库
  2. Android里string.xml使用html标签的方法
  3. 标签滑块旋转木马不工作在引导4
  4. {{content}}液体标签未显示博客帖子
  5. 【HTML5】H5新标签大实例 可直接运行
  6. 一天搞定HTML----标签类型与类型转换05
  7. HTML5实战与剖析之媒体元素(1、video标签和audio标签简介)
  8. 如何控制html代码中DL标签的颜色?
  9. phpstorm取消自动保存并标识修改的文件为星星标记

随机推荐

  1. android - 头中尾布局
  2. android baidupush
  3. Android中添加水平线
  4. Android graphics画图的点击事件处理
  5. Android中Acition和Category常量表
  6. Android Studio 无法启动虚拟机的问题
  7. android 混淆手册
  8. Android(安卓)- webview通过js调用Androi
  9. Android_android studio使用 9patch常见
  10. [转]Android事件处理