私は実際にdivを操作しようとしていますが、次の単純なテーブルレイアウトに相当するものを取得できないようです:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Table example</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
html, body {height: 100%}
.content {width: 750px; vertical-align: top}
</style>
</head>
<body style="margin: 0; padding: 0">
<table style="height: 100%; width: 100%; border-collapse: collapse">
<tr style="background-color: #666666">
<td></td>
<td class="content" style="height: 100px"><h1>Header Content</h1></td>
<td></td>
</tr>
<tr style="background-color: #BBBBBB">
<td></td>
<td class="content" style="background-color: #FFFFFF"><h1>Main Content</h1></td>
<td></td>
</tr>
<tr style="background-color: #666666">
<td></td>
<td class="content" style="height: 100px"><h1>Footer Content</h1>
</td>
<td></td>
</tr>
</table>
</body>
</html>
残しておきたい重要な要素:
実際のコンテンツは固定幅です。(この場合、750px)
ヘッダーとフッターの背景は、ページ幅の 100% に拡張されます。
メイン コンテンツの背景は水平方向には拡張されませんが、ヘッダーとフッターの間の領域を埋めるために垂直方向に拡張されます。
メインコンテンツの高さがそれほど高くない場合でも、フッターは常にページの下部にあります。
私は多くの戦略を試しましたが、div を使用してページの下部にフッターを保持する少なくとも 2 つの異なる方法を見つけました。残念ながら、メイン コンテンツが div にある場合、短いページのヘッダーとフッターの間のスペースを埋めるために垂直方向に拡張する方法はないようです。
編集: quirks モードでなくても機能することを示すように例を変更しました。上記が有効です。
編集2:
ほとんどの場合、javascript を使用してこれを行う方法を見つけました。だから、私の質問は次のとおりだと思います:javascriptなしでこれを行うにはどうすればよいですか。これが私が使用しているものです(これはfirefoxでのみ機能すると確信していますが、修正できます):
<script type="text/javascript">
function changeDiv() {
document.getElementById("content").style.minHeight = document.body.clientHeight - 200 + "px";
}
changeDiv();
window.onresize = changeDiv;
</script>
「コンテンツ」は、展開したいメインのコンテンツ div を指定します。