jsp页面!DOCTYPE问题

新建jsp页面默认的!DOCTYPE为
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
使用这个DOCTYPE,则margin:0 auto在ie无效
必须使用<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
这样margin:0 auto 在ie才有效

但是使用了<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >后,
jsp页面的其他信息则出现感叹号,
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
这些前面都有会感叹号。

到底要怎样才能又可以兼容ie的margin:0 auto,又不会出现感叹号呢?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

说明HTML文档的编写是遵循XHTML要求的。

我们都知道html允许一个标签没有结束标签,但是在xhtml规范中,所有的标签都必须有结束标签。


你的JSP页面内容为:

<meta http-equiv="pragma" content="no-cache">
   <meta http-equiv="cache-control" content="no-cache">
   <meta http-equiv="expires" content="0">    
   <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
   <meta http-equiv="description" content="This is my page">


每一个都没有结束标签。但是你又声明了遵循xhtml规范:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >

自然会报错.


 解决方法:修改为一下格式即可。

<meta http-equiv="pragma" content="no-cache"/>
   <meta http-equiv="cache-control" content="no-cache"/>
   <meta http-equiv="expires" content="0"/>    
   <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"/>
   <meta http-equiv="description" content="This is my page"/>

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-10
margin:0 auto在ie无效
这个不是DOCTYPE 的原因 应该是你代码写的不够规范,导致在ie下无效 ,
一般情况ie是支持margin:0 auto的 ,还有 你直接用<!DOCTYPE HTML>
试试看
相似回答