Six common incorrect usages in html5:
1. Do not use section as a substitute for div
(Learning video sharing : html video tutorial)
One of the most common mistakes people make when using tags is to arbitrarily equate HTML5's But now in HTML5, it will be like this: This usage is incorrect: ** is not a style container. The **section element represents the semantic part of the content used to help build a document summary. It should contain a header. If you're looking for an element that acts as a page container (like HTML or XHTML style), then consider writing the style directly to the body element, as Kroc Camen suggests. If you still need additional style containers, stick with divs. If you are still not sure about using Which element, then I suggest you refer to HTML5 sectioning content element flowchart The header element represents a set of introductory or navigational auxiliary text, which is often used As the header of the section. When the header has multiple layers of structure, such as sub-headers, subtitles, various logos, etc., use hgroup to combine h1-h6 elements as the header of the section. Since headers can be used multiple times in a document, this coding style may be popular: If your header element contains only one header element, then discard the header element. Since the article element already guarantees that the header will appear in the document summary, and the header cannot contain multiple elements (as defined above), why write extra code. Simply write it like this: Wrong use of If there is only one sub-header, hgroup will work fine by itself. . . Isn’t this nonsense? In this example, just remove the hgroup. Let the heading run smoothly. The second question is another unnecessary example: If header is the only child element It's hgroup, so what else needs to be done with the header? If there are no other elements in the header (such as multiple hgroups), just remove the header directly. (Web front-end learning exchange group: 328058344 No chatting, no entry unless you are interested!) 3. Don’t put all list-style links in nav With the introduction of HTML5, 30 With new elements (as of the time of the original publication), our choices in constructing semantic and structured tags have also become somewhat careless. That said, we shouldn't abuse hyper-semantic elements. Unfortunately, nav is an example of such an abuse. The specification of the nav element is described as follows: Main navigation Site search two Level navigation (slightly controversial) In-page navigation (such as a very long article) Since there is no absolute right or wrong, so According to an informal vote and my own explanation, in the following situations, whether you put it or not, I will not put it anyway Paging Control Social links (although some social links are also primary navigation, such as "About" and "Favorites") Tags for blog posts Blog Article classification Three-level navigation 过长的footer 如果使用section和hx也同样合适,那么不要用nav — Hixie on IRC 如果这些问题的答案是“不”,那就跟 四、figure元素的常见错误 figure以及figcaption的正确使用,确实是难以驾驭。让我们来看看一些常见的错误, 。其他视情况而定,但一开始可以问自己:“这个图片是否必须和上下文有关?”如果不是,那可能也不是(也许是个)。继续:“我可以把它移动到附录中吗?”如果两个问题都符合,则它可能是 。 另一个常见的关于figure的误解是它只被图片使用。figure可以是视频,音频,图表,一段引用文字,表格,一段代码,一段散文,以及任何它们或者其他的组合。不要把figure局限于图片。web标准的职责是精确的用标签描述内容。 五、不要使用不必要的type属性 这是个常见的问题,但并不是一个错误,我认为我们应该通过最佳实践来避免这种风格。 其实只需要这样写: 甚至指定字符集的代码都可以省略掉。Mark Pilgrim在Dive into HTML5的语义化一章中作出了解释。 六、form属性的错误使用 HTML5引入了一些form的新属性,以下是一些使用上的注意事项: autofocus autocomplete required 坦白的说,我很少看到这样的。以required为例,常见的是下面这种: 严格来说,这并没有大碍。浏览器的HTML解析器只要看到required属性出现在标签中,那么它的功能就会被应用。但是如果你反过来写equired=”false”呢? 解析器仍然会将required属性视为有效并执行相应的行为,尽管你试着告诉它不要去执行了。这显然不是你想要的。 required required=”” required=”required” 上述例子的正确写法应该是: 相关推荐:html5教程<!-- HTML 4-style code --><div id="wrapper">
<div id="header">
<h1 id="My-nbsp-super-nbsp-duper-nbsp-page">My super duper page</h1>
Header content </div>
<div id="main">
Page content </div>
<div id="secondary">
Secondary content </div>
<div id="footer">
Footer content </div></div>
Please do not copy these codes! This is wrong! <section id="wrapper">
<header>
<h1 id="My-nbsp-super-nbsp-duper-nbsp-page">My super duper page</h1>
<!-- Header content -->
</header>
<section id="main">
<!-- Page content -->
</section>
<section id="secondary">
<!-- Secondary content -->
</section>
<footer>
<!-- Footer content -->
</footer></section>
Based on the above ideas, the following are examples of correct use of HTML5 and some ARIA roles features (note that according to your own design, you may also need to add div) <body><header>
<h1 id="My-nbsp-super-nbsp-duper-nbsp-page">My super duper page</h1>
<!-- Header content --></header><div role="main">
<!-- Page content --></div><aside role="complementary">
<!-- Secondary content --></aside><footer>
<!-- Footer content --></footer></body>
2. Only use header and hgroup when needed
It is of course meaningless to write tags that do not need to be written. Unfortunately, I often see headers and hgroups misused for no purpose. You can read the two articles about header and hgroup elements for a detailed understanding. I briefly summarize the content as follows:
Abuse of header
Please do not copy this code! The header is not needed here -> <header>
<h1 id="My-nbsp-best-nbsp-blog-nbsp-post">My best blog post</h1>
</header>
<!-- Article content --></article>
<article>
<h1 id="My-nbsp-best-nbsp-blog-nbsp-post">My best blog post</h1>
<!-- Article content --></article>
On the topic of headers, I often see the wrong use of hgroup. Sometimes hgroup and header should not be used at the same time:
The first question is usually like this:
Please do not copy this code! No hgroup is needed here –> <hgroup>
<h1 id="My-nbsp-best-nbsp-blog-nbsp-post">My best blog post</h1>
</hgroup>
<p>by Rich Clark</p></header>
<header>
<h1 id="My-nbsp-best-nbsp-blog-nbsp-post">My best blog post</h1>
<p>by Rich Clark</p></header>
Please do not copy this code! No header is needed here –> <hgroup>
<h1 id="My-nbsp-company">My company</h1>
<h2 id="Established-nbsp">Established 1893</h2>
</hgroup></header>
<hgroup>
<h1 id="My-nbsp-company">My company</h1>
<h2 id="Established-nbsp">Established 1893</h2></hgroup>
The nav element represents a block in the page that links to other pages or other parts of this page; a block that contains navigation connections.
Note: Not all links on the page need to be placed in the nav element - this element is intended to be used as the main navigation block. To give a specific example, there are often many links in the footer, such as terms of service, home page, copyright statement page, etc. The footer element itself is sufficient to handle these situations. Although the nav element can also be used here, we usually think it is unnecessary.
The key word is "main" navigation. Of course we could spend the whole day telling each other what "primary" means. And I personally define it like this:
如果你不确定是否要将一系列的链接放在nav中,问你自己:“它是主要的导航吗?”为了帮助你回答这个问题,考虑以下首要原则:
为了方便访问,你会在某个“快捷跳转”中给这个nav标签加一个链接吗?
不是所有的图片都是figure
上文中,我曾告诉各位不要写不必要的代码。这个错误也是同样的道理。我看到很多网站把所有的图片都写作figure。看在图片的份上请不要给它加额外的标签了。你只是让你自己蛋疼,而并不能使你的页面内容更清晰。
规范中将figure描述为“一些流动的内容,有时候会有包含于自身的标题说明。一般在文档流中会作为独立的单元引用。”这正是figure的美妙之处——它可以从主内容页移动到sidebar中,而不影响文档流。
这些问题也包含在之前提到的HTML5 element flowchart中。
如果纯粹只是为了呈现的图,也不在文档其他地方引用,那就绝对不是
Logo并不是figure
进一步的说,logo也不适用于figure。下面是我常见的一些代码片段:<!-- 请不要复制这段代码!这是错的 --><header>
<h1>
<figure>  </figure>
My company name </h1></header>
<!-- 请不要复制这段代码!这也是错的 --><header>
<figure>  </figure></header>
在HTML5中,script和style元素不再需要type属性。然而这些很可能会被你的CMS自动加上,所以要移除也不是那么的轻松。但如果你是手工编码或者你完全可以控制你的模板的话,那真的没有什么理由再去包含type属性。所有的浏览器都认为脚本是javascript而样式是css样式,你没必要再多此一举了。<!-- 请不要复制这段代码!它太冗余了! --><link type="text/css" rel="stylesheet" href="css/styles.css" /><script type="text/javascript" src="js/scripts" /></script>
<link rel="stylesheet" href="css/styles.css" /><script src="js/scripts" /></script>
布尔属性
一些多媒体元素和其他元素也具有布尔属性。这里所说的规则也同样适用。
有一些新的form属性是布尔型的,意味着它们只要出现在标签中,就保证了相应的行为已经设置。这些属性包括:
<!-- 请不要复制这段代码! 这是错的! --><input type="email" name="email" required="true" /><!--
另一个错误的例子 --><input type="email" name="email" required="1" />
<!-- 请不要复制这段代码! 这是错的! --><input type="email" name="email" required="false" />
有三种有效的方式去使用布尔属性。(后两种只在xthml中有效)
<input type="email" name="email" required />
The above is the detailed content of Common incorrect usage in html5. For more information, please follow other related articles on the PHP Chinese website!

html5的div元素默认一行不可以放两个。div是一个块级元素,一个元素会独占一行,两个div默认无法在同一行显示;但可以通过给div元素添加“display:inline;”样式,将其转为行内元素,就可以实现多个div在同一行显示了。

html5中列表和表格的区别:1、表格主要是用于显示数据的,而列表主要是用于给数据进行布局;2、表格是使用table标签配合tr、td、th等标签进行定义的,列表是利用li标签配合ol、ul等标签进行定义的。

固定方法:1、使用header标签定义文档头部内容,并添加“position:fixed;top:0;”样式让其固定不动;2、使用footer标签定义尾部内容,并添加“position: fixed;bottom: 0;”样式让其固定不动。

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

html5中不支持的标签有:1、acronym,用于定义首字母缩写,可用abbr替代;2、basefont,可利用css样式替代;3、applet,可用object替代;4、dir,定义目录列表,可用ul替代;5、big,定义大号文本等等。

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

html5是指超文本标记语言(HTML)的第五次重大修改,即第5代HTML。HTML5是Web中核心语言HTML的规范,用户使用任何手段进行网页浏览时看到的内容原本都是HTML格式的,在浏览器中通过一些技术处理将其转换成为了可识别的信息。HTML5由不同的技术构成,其在互联网中得到了非常广泛的应用,提供更多增强网络应用的标准机。

3种取消方法:1、给td元素添加“border:none”无边框样式即可,语法“td{border:none}”。2、给td元素添加“border:0”样式,语法“td{border:0;}”,将td边框的宽度设置为0即可。3、给td元素添加“border:transparent”样式,语法“td{border:transparent;}”,将td边框的颜色设置为透明即可。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
