为什么我的网络浏览器上没有HTML渲染?

Chu*_*cky 2 html rendering html-rendering

它只是在谷歌浏览器中显示如下:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

为什么不按预期转变?

编辑:是的文件确实有.html文件名.根据我正在使用的教程,我不确定它是否应该需要一个标题,它说它应该正确渲染而没有一个?所有这些都是新的,所以我不确定.

编辑:当我用textedit打开它时,我得到了这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="1038.35">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
  </style>
</head>
<body>
<p class="p1">&lt;html&gt;</p>
<p class="p1">&lt;head&gt;</p>
<p class="p1">&lt;title&gt;Hello World!&lt;/title&gt;</p>
<p class="p1">&lt;/head&gt;</p>
<p class="p1">&lt;body&gt;</p>
<p class="p1">&lt;h1 align="center"&gt;Hello World!&lt;br/&gt;Welcome to My Web Server.&lt;/h1&gt;</p>
<p class="p1">&lt;/body&gt;</p>
<p class="p1">&lt;/html&gt;</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我根本不记得这样保存它.

ins*_*ite 9

你是如何创建网页的?您使用的编辑器可能会转换html,使其显示"<"而不是呈现它们

在记事本中打开文件,检查内容是否:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

并不是

&lt;html&gt;
......
&lt;/html&gt;
Run Code Online (Sandbox Code Playgroud)

确保使用.html扩展名保存文件


Mr *_*ose 5

它应该由浏览器呈现,而不是Web服务器.检查HTTP标头"Content-Type".它应该读取类似"Content-Type:text/html; charset = utf-8"的内容.

鉴于您使用Chrome,请使用以下步骤加载开发人员工具;

  1. 右键单击页面 - >选择"检查元素"
  2. 转到网络选项卡
  3. 加载您要检查的页面
  4. 选择要检查标题的页面的URL等