Section is probably the most obscure of the new tags. According toHTML 5 definition , a chapter is a collection of topics of content, usually after the header tag and before the footer tag. However, sections can be nested within each other if necessary.
In our example above, the p marked by "content" is a good choice to become a section. In addition, within that section, we can add sections according to the content.
Remember that a page can have multiple article tags; for example, a blog homepage may have the latest ten articles, each of which is contained in an article tag. Articles can also be divided into multiple paragraphs by using the section tag, however you need to be a little careful when planning your structure, otherwise you can easily end up with some ugly hodgepodge of tags.
Another rather vague tag, the aside element is used for content that is "irrelevant to the content of the main body stream that makes up the document." That means an additional comment, an inline footnote, acitation , annotations, or more typical sidebar content like the one you see on the right side of this article.
can be used in all of these situations, although the quotes in your sidebar are very different from the tag cloud.
No one said HTML 5 is perfect!
The use of Footer should also be obvious, except maybe you don’t know that you can have multiple footers. In other words, in addition to the main subscripts typically found at the bottom of most pages, paragraphs can also contain subscripts.
Putting them together
Let’s rewrite our original example using new tags:
Very clear and easy to understand ,Is not it? Some notes: We can include our
My Article title in the header tag. I didn’t do this because the h1 element already conveys the meaning of the title, but if you also have the publication date, byline, or other data at the top of your article, adding a header container tag to the tag set is a good option.
Also note that we can add a second footer element under the article element to include page navigation, related articles or other content.
Writing styles for new tabs
In most browsers, all you need to do is apply a style sheet on a new tab as you would normally do, simply defining your styles. But please make sure to add the display:block; rule to every element, no matter what, from now on. Over time, as browsers begin to standardize and support new elements, that won't be necessary.
For example, let's apply some styles to our header:
Remember, you can still add class and ID attributes to these tags. So, if you want to style a navigation individually, you can easily add a class or style to the tag, like this:
Then you can apply a Style:
Compatible with old browsers
But wait, what about IE? These styles don't work under IE6 at all. If you still need to support legacy browsers like IE6, here's a solution. IE6 parses and displays these tags fine, but you can't set any CSS on them. The solution is to use a little JavaScript.
We just need to let IE set styles for the HTML 5 tags we created using the createElement method. Add this in the head tag of your HTML 5 file. Alternatively, you can save it in a specific file and include it that way.
I know what you're thinking: "Brother, you didn't define a MIME type for that script tag at all."
You don't need to specify it in the HTML 5. Do these things. In HTML 5, all scripts are assumed to be of type="text/javascript", so there's no need to clutter your script tags with attributes (unless your script isn't JavaScript).
This solves the problem with IE, but we're not out of the woods. It turns out there is a bug in the Gecko rendering engine that causes some versions of Firefox 2 and Camino to get stuck on these tabs.
There are two ways to deal with this bug, neither of which is ideal. For more details, please see this article byHTML5doctor . This article also comes with a handy script that enables all HTML 5 elements.
Keep in mind that although Firefox 2 usage has quickly dropped below 10% of all website traffic, simply ignoring this bug may still depend on your site's visitors.
Now you can use HTML 5, but will you use it?
The short answer is: we do.
The more complicated thing is: it depends on the site. If you're accused of remaking the CNN homepage, well, you might resist a little until browser support gets better. But if you want to revamp your blog, we have your back. Here are some WordPress plugins that can help you if you are using such a popular publishing system. Here is aHTML 5 theme created by Jeff Starr.
Also, try the site-focusedHTML 5 Gallery and check out the source code to see what they do.
Still, if IE's shortcomings stop you, consider this: Even Google is using the HTML 5 document type on their mainsearch page. Even if you don't use all the new structural tags, you can at least take advantage of concise script declarations and some non-structural semantic tags that we'll cover next time.
【Related recommendations】
1.HTML5 free video tutorial
2.Detailed explanation of how to add voice function to H5 input box
3.What should I do if the input box is blocked when creating a virtual keyboard in H5?
4.Detailed explanation of the method of implementing full-screen playback on WeChat in HTML5
5.Detailed explanation of browser compatibility issues with H5 new tags
The above is the detailed content of Overall overview of how to use H5 to create web pages. For more information, please follow other related articles on the PHP Chinese website!