8

使用最新版本的 Google Chrome 浏览我的网站并使用 F12 查看源代码时,和之间的所有内容都<head>显示为</head>空。在 Firefox 和 IE 的最新版本中,一切都正常显示。

实际上内容被移动到谷歌浏览器的正文中。

这显然不是 CSS 问题。我正在使用 Twitter Bootstrap CSS 和 JS,以及一个 MVC PHP 框架。有人有提示吗?

这是我的 document.html 页面:

<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title><?php echo (Template::$titre); ?></title>

<?php foreach(Template::$meta as $key=>$value): ?>
        <meta name="<?php echo $key; ?>" content="<?php echo $value; ?>" />
<?php endforeach; ?>

<link rel="shortcut icon" href="<?php echo WEB; ?>assets/style/favicon.ico" type="image/x-icon" />  

<link rel="stylesheet" href="<?php echo WEB; ?>assets/style/bootstrap.min.css" />   
<link rel="stylesheet" href="<?php echo WEB; ?>assets/style/bootstrap-responsive.min.css" />    
<link rel="stylesheet" href="<?php echo WEB; ?>assets/style/main.css" />    
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>

<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head> 
<body>
<?php require Template::child(); ?>
(...)

Firebug查看的源代码:

<html lang="fr"><head></head><body>?


<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<title>Vélos d'occasion dans toute la France</title>
<meta name="keywords" content="velos d'occasion, velos dans toute la France, velos occasion Toute la france, velo occasion, velo">
<meta name="description" content="Petites annonces de velos d'occasion dans toute la France, velo d'occasion à vendre Toute la france">

<link rel="shortcut icon" href="/assets/style/favicon.ico" type="image/x-icon"> 

<link rel="stylesheet" href="/assets/style/bootstrap.min.css">  
<link rel="stylesheet" href="/assets/style/bootstrap-responsive.min.css">   
<link rel="stylesheet" href="/assets/style/main.css">   
<link href="http://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">

<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->


<section id="maincontainer">
<div class="container">
(...)

编辑:问题解决了,记事本++是用UTF8编码的,我改成ANSI并且工作正常。

4

5 回答 5

6

您的文档开头有某种格式错误的字符。

我通过 W3C 验证器运行了您的页面,它显示:

错误第 1 行,第 1 列:在没有先查看文档类型的情况下找到非空格字符。预期<!DOCTYPE html>

http://validator.w3.org/check?uri=http%3A%2F%2Fveloccasion.net%2F&charset=%28detect+automatically%29&doctype=Inline&group=0

这似乎导致 Chrome 放弃您的文档类型并以 Quirks 模式呈现页面,您可以通过有趣的按钮和文本字段高度看到。尝试在 DOCTYPE 之前删除任何奇怪的东西(或删除 DOCTYPE 并重新输入)

于 2012-05-22T04:49:10.723 回答
2

要以 Elijah 的回答为基础,请使用 CTRL+U 在 chrome 和 firefox 上查看源代码。

我刚刚检查了 chrome,它不是空的。

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>Veloccasion - V&eacute;los d'occasion dans toute la France</title>
<meta name="keywords" content="velos d'occasion, velos dans toute la France, velos occasion Toute la france, velo occasion, velo" />
<meta name="description" content="Petites annonces de velos d'occasion dans toute la France, velo d'occasion &agrave; vendre Toute la france" />
<meta name="author" content="Veloccasion.net" />

<link rel="shortcut icon" href="/assets/style/favicon.ico" type="image/x-icon" />   

<link rel="stylesheet" href="/assets/style/bootstrap.min.css" />    
<link rel="stylesheet" href="/assets/style/bootstrap-responsive.min.css" /> 
<link rel="stylesheet" href="/assets/style/main.css" /> 
<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>

<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

于 2012-05-22T04:21:10.423 回答
1

我找到了!

在 chrome 中按 CTRL+SHIFT+I,

...在<body>标签之后有一行很多空白文本。找到它,然后删除它,空白就消失了。不知道是什么原因造成的,因为我没有你的代码。

于 2012-05-22T04:45:59.540 回答
1

F12 不是查看源代码。F12 是 dom 检查器。有没有可能你只是看到头塌了?这是默认显示的方式。

编辑:

发现你的问题:

    <link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>

那个标签没有关闭。你需要结束它/>

编辑:

可能是您/>在此行之前需要一个空格:

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
于 2012-05-22T04:18:01.843 回答
-1

希望能帮助到你

下面的行

<link href="http://fonts.googleapis.com/css?family=Lobster"
 rel="stylesheet" type="text/css

注意“?” 在其中尝试删除此行并查看源代码

于 2012-05-22T04:26:30.977 回答