HTML标签p和div的不同

欢迎访问我的新博客:http://www.milkcu.com/blog/

原文地址:http://www.milkcu.com/blog/archives/1370482200.html

标题: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 have semantic difference - 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 should describe the 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> are block-level elements which means that most browsers will treat them in a similar fashion.

后记

原文是段很美妙的文字,也许被我翻译的凌乱了许多。怕别人看不懂我写的,特放上原文。这样的翻译就当作自娱自乐吧,在做的时候应该能学到点什么吧,虽然思想无法完全用语言表达。

(全文完)

转载于:https://www.cnblogs.com/milkcu/archive/2013/06/06/3808929.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值