是< div>标记“< p>标签? [英] Is the <div> tag ever an undesirable alternative to the <p> tag?

查看:120
本文介绍了是< div>标记“< p>标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到< p> 标签在其他代码中使用了很多,但从未在我自己的工作中使用过它。



我想知道使用< div> 标签有何优势?


  1. 通过合并< p> 吗? >
    标记到我的页面中?

  2. 使用< div> $ b是否存在任何缺点? / code> tags < p>



解决方案

DIV表示页面上的单独部分,它与其他部分没有语义关联。使用P标签,你可以指出这段文本被分成了几段,但它仍然是一个单独的实体。



ADDED:有了语义,人们通常会提到可能性从HTML中提取关于页面的各种元素代表以及它们如何相互关联的信息,而不是将整个HTML视为要呈现的标记。例如,当您执行菜单时,建议您使用UL(无序列表)作为此目的,因为可以从标记中了解到特定列表中包含的所有LI(列表项)可能意味着同一水平。我知道这对屏幕阅读器有帮助,因为您试图让标记尽可能语义丰富。



如果您不关心这一点,那么无论使用DIV还是Ps,渲染结果几乎没有区别。您可以使用CSS设计风格,以达到相同的外观和感觉。

语义HTML仍然不是绝对的好东西。对于许多人来说,语义学不会增加任何价值,因为他们只希望他们的页面能够正确呈现。这就是为什么关于是否使用表格进行标记(并添加不属于它的语义)或坚持CSS的持久讨论不会很快结束的原因。


I see the <p> tag used a lot in the code of others but have never used it in my own work.

I'm wondering what advantage this gives over using a <div> tag?

  1. Are there any benefits I could get from incorporating the <p> tag into my pages?

  2. Is there any disadvantage in only using <div> tags without <p>?

解决方案

DIV indicates a separate section on a page, which is not semantically connected to the others. With P tags you indicate that this piece of text is broken into paragraphs but it still stays a single entity.

ADDED: With "semantics" people usually refer to the possibility to extract information from HTML as to what various elements of a page represent and how they are related to each other, as opposed to treating the whole HTML as just a markup to be rendered. For example, when you do menus it is recommended that you use ULs (unordered list) for that purpose, because it will be possible to learn from the markup that all LIs (list items) contained within a particular list probably mean choice options of the same level. I know it is helpful for screen readers for impaired people that you try to make your markup as semantic-rich as possible.

If you're not concerned with this, then it is virtually no difference for the rendered result whether you use DIVs or Ps. You can style both with CSS to achieve the same look and feel.

Semantic HTML is still not "the absolute good" to be strived for. For many people semantics does not add any value as they wish just that their pages are rendered correctly. That's why the ever-lasting discussion on whether to use tables for markup (and add semantics where it does not belong) or stick to CSS is not going to end any soon.

这篇关于是&lt; div&gt;标记“&lt; p&gt;标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆