[英]<doctype html> is messing up my CSS
簡而言之,我想要一個right div float
垂直延伸100%
但它只有在我的html中不包含<doctype>
時才有效
在今天的標准中,我真的要添加<doctype>
嗎?
這是Internet Explorer中的結果:
這只是簡單的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>
在今天的標准中,我真的要添加
<doctype>
嗎?
你不必做任何事情,但由於沒有DOCTYPE的基本上聲稱你符合(在長期的寬松感)一個未知/不一致的“怪癖”的標准。
我想解決方案就像將父容器的高度設置為100%或特定像素高度一樣簡單。
HTML
和BODY
元素上設置高度。 工作示例: 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%。 這需要更多的努力(但仍然在標准內工作良好)。
如果您正在考慮考慮使用IE(任何版本,請不要偏離本主題),那么您最好指定DOCTYPE。 我已經看到許多頁面沒有通過IE正確地進入着名的Quirks模式。
使用此代碼
<!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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.