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

实际上,内容已移至 google Chrome 的正文中。

这显然不是 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">
(...)

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

有帮助吗?

解决方案

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

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

错误第 1 行第 1 列:在没有首先看到Doctype的情况下发现的非空间角色。预期的 <!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 并重新键入)

其他提示

要以 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]-->

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"/>

我找到了!

在 Chrome 中按 CTRL+SHIFT+I,

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

希望能帮助到你

下面的行

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

注意“?”在其中尝试删除这一行并查看源

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top