闻道华东seo,清音浊世录,儿童套房
什么是 xhtml?xhtml 是以 xml 格式编写的 html。
为什么使用 xhtml?因特网上的很多页面包含了"糟糕"的 html。如果在浏览器中查看,下面的 html 代码运行起来非常正常(即使它并未遵守 html 规则):
1 <html> 2 <head> 3 <title>this is bad html</title> 4 <body> 5 <h1>bad html 6 <p>this is a paragraph 7 </body>
xml 是一种必须正确标记且格式良好的标记语言;今日的科技界存在一些不同的浏览器技术。其中一些在计算机上运行,而另一些可能在移动电话或其他小型设备上运行。小型设备往往缺乏解释"糟糕"的标记语言的资源和能力。所以 - 通过结合 xml 和 html 的长处,开发出了 xhtml。xhtml 是作为 xml 被重新设计的 html。
与 html 相比最重要的区别:
文档结构
xhtml doctype 是强制性的
元素语法
属性语法
<!doctype ....>是强制性的
xhtml 文档必须进行 xhtml 文档类型声明(xhtml doctype declaration)。<html>, <head>, <title>, 和 <body> 元素也必须存在,并且必须使用 <html> 中的 xmlns 属性为文档规定 xml 命名空间。下面的例子展示了带有最少的必需标签的 xhtml 文档:
1 <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" 2 "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> 3 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 6 <head> 7 <title>title of document</title> 8 </head> 9 10 <body> 11 ...... 12 </body> 13 14 </html>
xhtml 元素必须合理嵌套
在 html 中,一些元素可以不互相嵌套,像这样:
1 <b><i>this text is bold and italic</b></i>
在 xhtml 中,所有的元素都必须互相合理地嵌套,像这样:
1 <b><i>this text is bold and italic</i></b>
xhtml 元素必须有关闭标签
1 错误示例: 2 <p>this is a paragraph 3 <p>this is another paragraph
1 正确示例: 2 <p>this is a paragraph</p> 3 <p>this is another paragraph</p>
空元素必须包含关闭标签
1 错误示例: 2 a break: <br> 3 a horizontal rule: <hr> 4 an image: <img src="happy.gif" alt="happy face"> 5 正确示例: 6 a break: <br /> 7 a horizontal rule: <hr /> 8 an image: <img src="happy.gif" alt="happy face" />
xhtml 元素必须是小写
1 错误示例: 2 3 <body> 4 <p>this is a paragraph</p> 5 </body> 6 正确示例: 7 8 <body> 9 <p>this is a paragraph</p> 10 </body>
属性名称必须是小写
1 错误示例: 2 3 <table width="100%"> 4 正确示例: 5 6 <table width="100%">
属性值必须有引号
1 错误示例: 2 <table width=100%> 3 正确示例: 4 <table width="100%">
不允许属性简写
1 错误示例: 2 3 <input checked> 4 <input readonly> 5 <input disabled> 6 <option selected> 7 正确示例: 8 9 <input checked="checked"> 10 <input readonly="readonly"> 11 <input disabled="disabled"> 12 <option selected="selected">
如何将 html 转换为 xhtml?
关闭所有的空元素
推荐网址:
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
css3 flex布局 justify-content:space-between 最后一行左对齐
网友评论