简体   繁体   English

使用HTML5标签有什么好处 <article> , <section> , <figure> , <header> , <footer> , <nav> ?

[英]What is the benefit of using HTML5 tags like <article>, <section>, <figure>, <header>, <footer>, <nav>?

There are some semantic tags like <article>, <section>, <figure>, <header>, <footer>, <nav> in HTML5. HTML5中有一些语义标记,例如<article>, <section>, <figure>, <header>, <footer>, <nav> Why should I use them, instead of <div> or <span> ? 为什么要使用它们而不是<div><span> Is there any optimization? 有没有优化?

Readability 可读性

When people use "You're just arguing semantics!" 当人们使用“您只是在争论语义学!”时 as a defense in an argument, it's meant to imply they're trying to say the same thing in different ways. 作为论点的辩护,这意味着他们试图以不同的方式说同一件事。 While it is an ok argument here, it's not as necessarily true. 虽然这是一个确定的说法在这里,它不是一定是真的。

Using the more semantic html tags will make your HTML more readable and clear, while also allowing you to have specific CSS related to tags, and not necessarily require custom classes for divs. 使用更多语义的html标签将使您的HTML更具可读性和清晰性,同时还允许您拥有与标签相关的特定CSS,并且不一定需要div的自定义类。 Now one could argue that you need that css in a class or a tag either way, but at some point, every programmer has preferences. 现在,有人可能会争辩说,您需要以任何一种方式在类或标记中​​使用CSS,但是在某些时候,每个程序员都有首选项。 Some write for (int i =0; i < count; < i++) {} and some write for (int i = count; i > 0; i--;) {} . 有些for (int i =0; i < count; < i++) {}写,有些for (int i = count; i > 0; i--;) {}

It's also worth mentioning that those tags, similar to <p> and <ul> have default CSS properties depending on your browser, so you can get away with some easy styling for newer pages using those tags as opposed to creating everything from scratch with divs. 还值得一提的是,类似于<p><ul>这些标签具有默认的CSS属性,具体取决于您的浏览器,因此您可以使用这些标签对新页面进行一些简单的样式设置,而无需使用div从头开始创建所有内容。

At the end of the day, whatever helps you write the best code is what you should use. 归根结底,应该使用什么来帮助您编写最佳代码。 But be aware of other options as you will likely have to work with someone who has different preferences than you. 但是请注意其他选择,因为您可能需要与偏好与您不同的人一起工作。

What is the benefit of using HTML5 tags like <article> , <section> , <figure> , <header> , <footer> , <nav> ? 使用HTML5标签(例如<article><section><figure><header><footer><nav>什么好处?

HTML marks up the structure of the document. HTML标记了文档的结构。

It tells the user agent: 它告诉用户代理:

  • this element is a heading 这个元素是一个标题
  • this element is a paragraph 这个元素是一个段落
  • this element is a quote 这个元素是一个报价

You could , theoretically, use: 从理论上讲,您可以使用:

  • <div class="heading">
  • <div class="paragraph">
  • <span class="quote">

But then the user-agent wouldn't know (at any level) what those divs and spans represent. 但是,那么用户代理将不会(在任何级别上)知道这些div和span代表什么。

For this reason we use elements which describe the structure of the document. 因此,我们使用描述文档结构的元素。

That's the entire purpose of markup. 这就是标记的全部目的 It isn't for anything more than that. 除此之外,它没有其他用途。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CodedUI GetChildren()不返回带有HEADER,SECTION,ARTICLE,NAV等HTML5标签的子级 - CodedUI GetChildren() doesn't return children with HTML5 tags like HEADER, SECTION, ARTICLE, NAV 在引擎盖下,HTML5标签(文章,部分,旁边,页眉,页脚)是否像div一样实现? - Under the hood, are HTML5 tags (article, section, aside, header, footer) implemented just like div? HTML5语义标签(文章,页脚,标题)的降级问题 - Degradation issues for HTML5 semantic tags (article, footer, header) 什么是HTML5标签的替代品 <figure> 和 <section> 在jQuery中使用较旧的浏览器? - What are alternatives to the HTML5 tags <figure> and <section> for older browsers in jQuery? 如何使用 <section> 和 <article> HTML5中添加标签? - How to use <section> and <article> tags in HTML5? HTML5:页脚,页眉和文章 - HTML5: Sticky footer, header and article 页眉/页脚/导航标签-在IE7,IE8和浏览器中,不支持HTML5的标签会发生什么变化? - header/footer/nav tags - what happens to these in IE7, IE8 and browsers than don't support HTML5? HTML5 <section> 在里面 <article> 和标题 - HTML5 <section>'s inside <article> and header 使用CSS为特定标签(页眉,导航,文章,页脚)中的链接设置样式,而无需使用类或ID? - Using CSS to style links within specific tags (header, nav, article, footer) without classes or id's? 如何正确地将页面与页眉,导航,节和页脚对齐// HTML5和CSS - How to properly align a page with header, nav, section and footer // HTML5 and CSS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM