即使我删除了 BODY 标签,也会添加它

BODY tag is added even when I delete it

我有一个奇怪的问题,正文不在我在代码中写的地方。 首先它在 head 标签之前加载,现在它在 header 标签之前甚至认为它在之后开始。 另外,如果我删除它,它会在 head 和 header 标签之前的一些奇怪的地方生成.... 有什么解决办法吗?

这是开头:

<!DOCTYPE html> <!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> <!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]--> <!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head>   <meta content="IE=edge" http-equiv="X-UA-Compatible">   <meta content="width=device-width, initial-scale=1" name="viewport">   <title>HUB International</title>   <meta content="A free HTML5/CSS3 template made exclusively for Codrops" name="description">   <meta content="html5 template, css3, one page, animations, agency, portfolio, web design" name="keywords">  <meta content="" name="author"><!-- Bootstrap -->   <!-- CPIT CSS -->  <link href="Assets/CPIT/css/main.css" rel="stylesheet">

  <!-- CSS -->   <link href="Assets/HUB/css/bootstrap.min.css" rel="stylesheet">     <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">



  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->   <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->   <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]--> </head> <!--[if lt IE 7]>
        <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
        <![endif]--> <!-- open/close -->   <header class="new-header"> <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script>  <script src="Assets/CPIT/scripts/custom.js"></script>-->

    <div class="container">
      <a href="#"><img alt="Hub Logo" class="logo roundel" src="https://www.hubinternational.com/Assets/Hub/images/logo/HUB-Horizontal-With-Roundel.png"></a>
      <nav class="main-site-nav">
        <ul class="reset">
          <li>
            <a class="btn gs-btn contact_" href="https://www.hubinternational.com/contact-us/">Contact Us</a>
          </li>
        </ul>-
      </nav>
    </div>   </header>

  <!-- End Header     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"> </script> 

<script>window.onload=function(){function a(a,b){var c=/^(?:file):/,d=new XMLHttpRequest,e=0;d.onreadystatechange=function(){4==d.readyState&&(e=d.status),c.test(location.href)&&d.responseText&&(e=200),4==d.readyState&&200==e&&(a.outerHTML=d.responseText)};try{d.open("GET",b,!0),d.send()}catch(f){}}var b,c=document.getElementsByTagName("*");for(b in c)c[b].hasAttribute&&c[b].hasAttribute("data-include")&&a(c[b],c[b].getAttribute("data-include"))};</script> <div data-include="header.html"></div>

<script src="Assets/CPIT/scripts/custom.js"></script>-->

<body>

将元素放入 <html> 而不是 <head><body> 是一个大禁忌

原因是浏览器试图解决您违反 HTML 规范的问题。 According to MDN<html>元素允许的内容如下:

Permitted content

One <head> element, followed by one <body> element.

这意味着,如果 HTML 被解析为违反此规范,则允许浏览器尝试以其认为合适的任何方式解析它,包括如您所述,注入 <body> 标记你不想要的地方。

tl;博士

只需将您的标签分别放在它们所属的 <head><body> 中,您就不会有任何问题。