Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

html - How to use HTML5 features with XHTML

I need some help with web programming. I have to do this assignment from school and the prof has given details on the structuring. One of them is that my site should be XHTML compliant (Strict or Transitional). Another is that I need to use at least one HTML5 feature. How do I use an HTML5 feature if none of the new tags will validate with XHTML?

I am declaring it as XHTML 1.0 Transitional.

Here is my HTML code where I am having trouble.

<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="#">Header1 </a></h1>

<nav><ul>
<li class="active"><a href="#">home</a></li>
<li><a href="#">portfolio</a></li>
<li><a href="#">blog</a></li>
<li><a href="#">contact</a></li>
</ul></nav>

</header>
</body>

In the line with header and nav, it says the elements are undefined and that there are no attributes id and class in header. Please help.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The interpretation of the assignment that seems to make most sense is that you are required to use XHTML linearization of HTML5, also known as XHTML5. This simply means that you use HTML5 like anyone else but do that using general XML principles.

In the example case, this would mean the following markup:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body id="index" class="home">
<header id="banner" class="body">
<h1><a href="#">Header1 </a></h1>

<nav><ul>
<li class="active"><a href="#">home</a></li>
<li><a href="#">portfolio</a></li>
<li><a href="#">blog</a></li>
<li><a href="#">contact</a></li>
</ul></nav>

</header>
</body>
</html>

The XHTML 1.0 doctypes are something quite different. They define fixed versions of HTML, so you cannot use, in the static markup, anything not allowed by those versions, i.e. anything that is new in HTML5 as compared with XHTML 1.0 and HTML 4.01 (which is what “HTML5 feature” probably means in the assignment). The requirement “XHTML compliant (Strict or Transitional)” is obscure, but if it is meant to refer to XHTML 1.0 specifically, then the assignment is self-contradictory (unless you are supposed to use client-side scripting to get to “HTML5 features”).

(This answer was largely rewritten thanks to @Alohci’s comments.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...