<doctype html =“”>搞乱了我的CSS </doctype>

时间:2012-12-13 05:24:08

标签: html css internet-explorer doctype

简而言之,我希望right div float能够垂直延伸100% 但它只有在我的html

中不包含<doctype>时才有效

在今天的标准中,我真的需要添加<doctype>吗?

这是Internet Explorer中的结果:

doctype issues

这只是简单的html

<html>
<head>
<style type="text/css">
html, body {
padding:0;
margin:0;
height:100%;
}
#wrap {
background:red;
height:100%;
overflow:hidden;
}
#left {
background:yellow;
float:left;
width:70%;
min-height:100%;
}
#right {
background:pink;
float:right;
width:30%;
min-height:100%;
}
</style>

<body>
<div id="wrap">
<div id="left"> Content </div>
<div id="right"> Side Content </div>
</div>
</body>
</html>

3 个答案:

答案 0 :(得分:6)

  

在今天的标准中,我真的需要添加<doctype>吗?

你没有做任何事情,但缺少DOCTYPE基本上断言你(在最宽松的意义上)符合未知/不一致的“怪癖”标准。

我想解决方案就像将父容器的高度设置为100%或特定像素高度一样简单。

  • 确保在HTMLBODY元素上设置了高度。
  • 确保在任何父容器上设置高度。

工作示例:http://jsfiddle.net/7xxFj/

<div id="one">
    First column
</div>
<div id="two">
    second column
</div>​

HTML, BODY { height: 100%; }
#one { height: 100%; width: 30%; float: left; background-color: red; }
#two { height: 100%; width: 70%; float: left; background-color: blue; }

正如@BoltClock在评论中指出的那样,你可能想要一个可以超过100%的布局。这需要更多的努力(但仍然在标准范围内很好地工作)。

This article显示了几种实现具有相等列高的布局的方法。更多methods here

答案 1 :(得分:2)

如果您正在考虑考虑使用IE(任何版本,请不要偏离本主题),那么您最好指定DOCTYPE。我已经看到许多页面没有通过IE正确地进入着名的Quirks模式。

答案 2 :(得分:1)

使用此代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
html, body {
padding:0;
margin:0;
height:100%;
}
#wrap {
background:red;
height:100%;
overflow:hidden;
}
#right {
background:blue;
float:left;
width:30%;
height:100%;
}
#left {
background:yellow;
float:left;
width:70%;
height:100%;
}
</style>
</head>
<body>
<div id="wrap">
<div id="left"> Content </div>
<div id="right"> Side Content </div>
</div>
</body>
</html>
相关问题