标签弹出标记

时间:2015-03-05 13:36:59

标签: html css web

当我在html中用tag编写代码时,发生了一些奇怪的事情:

<div id="header1" style="background-color:white;color:grey;font-size:20px;">
    <img id="MainImg" src="StatMarketlogo_final.gif" style="float:left;">
    <b>Hello Amit,you last login was on 5/3/2015</b>
</div>

它从<head>代码中弹出,然后转到<body>代码。 发生了什么? 我这样做是因为我希望我的头部背景与身体背部颜色​​不同。所以我希望他们会有不同的标签。

2 个答案:

答案 0 :(得分:3)

head元素的结束标记是可选的。

body元素的开始标记是可选的。

head元素内不允许使用div元素。 (Div元素包含内容,head元素不应包含任何内容,只包含<title><link>等元数据到样式表。)。

在有头尾标记之前放置div开始标记将隐式结束head元素并启动body元素。


听起来<div>实际上应该是<header> {strong} <body>之内和<main>之前。

答案 1 :(得分:2)

HEAD标签不是您认为的那样。它包含有关文档的信息:http://www.w3schools.com/html/html_head.asp

尝试将div更改为标题标记,然后将其分别设置为文档的其余部分。这两个都应该保留在body标签内:

 <header id="header1" style="background-color:white;color:grey;font-size:20px;">
     <img id="MainImg" src="StatMarketlogo_final.gif" style="float:left;">
     <b>Hello Amit,you last login was on 5/3/2015</b>
 </header>

 <div class="some-content" style="background-color:red;">
   Some content
 </div>