问题描述
我有一个HTML页面,该页面使用CSS和JavaScript来在调整浏览器窗口大小时将页面内容居中放置在浏览器中间.
I have an HTML page that uses CSS and JavaScript to center the content of the page in the middle of the browser when the browser window is resized.
当我使用标准HTML5 Doctype声明时,所有浏览器都将完全忽略我的CSS文件.我不知道为什么.当我删除HTML5 Doctype时,它们又可以正常工作了.该页面在Chrome,FF和IE中都显示相同(错误).都错了
When I use the standard HTML5 Doctype declaration, all browsers completely ignore my CSS files. I have no clue why. When I remove the HTML5 Doctype, then they work just fine again. The page displays the same (incorrectly) in both Chrome, FF and IE. All wrong.
这是页面的开头:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/stylesheet-mobile.jsp" >
<link rel="stylesheet" type="text/css" href="/stylesheet-mobile-frontpage.jsp" >
<meta name="viewport" content="width=device-width" />
<script src="/javascript/jquery/jquery-1.8.3.min.js"></script>
<script src="/javascript/resize-fit.jsp"></script>
<link rel="shortcut icon" href="/favicon.ico" />
</head>
有任何线索吗?
推荐答案
您确定要为这些文件发送正确的内容类型标头吗?我看到您正在使用Java生成CSS.没有适当的内容类型,浏览器可能无法理解或尊重它们.
Are you sure you're sending the right content-type header for those files? I see you're using Java to generate the CSS. Without the proper content type the browser may not understand or honor them.
Content-type: text/css
这篇关于使用HTML5 doctype时会忽略CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!