これはまだ使っても大丈夫ですか?古いブラウザで防弾するにはどうすればよいですか?
height: -moz-calc(100% - 70px);
height: -webkit-calc(100% - 70px);
height: calc(100% - 70px);
これが具体的に私が達成しようとしていることです。
- 全幅/固定高ヘッダー
- 全幅と全高からヘッダーの高さを差し引いたものを伸ばす Slider 。
- スライダーの縦横中央に配置された見出しブロック
- スライダーの下部から常に一定の高さである Controls ブロック
これまでに達成できたもののイメージを次に示します。上記の太字の部分を除いて、ほぼ完璧です。スライダー (黒い領域) は現在 100% の高さで伸びており、ヘッダーの後ろに流れています。これは画像には適していません。
パディングまたはマージンを追加すると、スライダーの高さが 100% を超えて拡張され、スクロールバーが表示されます。上記の高さの計算を使用すると修正されるようですが、私の理解でcalc()
は、IE 7、IE 8、iOS 5 以下、または Android と互換性がありません。
この問題のより良い修正はありますか? jQuery は問題ありませんが、存在する場合は CSS ソリューションを使用したいと思います。
ここに私のHTMLがあります:
<div class="header">
<h1>Header - Full Width + 70px Height</h1>
</div>
<div class="slider">
<div class="headline">
<div class="headline-container"><!-- for table-cell vertical centering -->
<h1>Headline Block</h1>
<p>Centered Horizontally & Vertically in the Slider Block</p>
</div>
</div>
<div class="controls">
<h2>Controls - Centered Horizontally & 40px from bottom of container</h2>
</div>
</div>
ここに私のCSSがあります:
html, body {
width: 100%;
height: 100%;
margin: 0; padding: 0;
}
h1, h2, p {
margin: 0;
padding: 0;
}
.header {
position: absolute;
width: 100%;
height: 70px;
background-color: #888;
z-index: 9999;
}
.header h1 {
color: #fff;
text-align: center;
}
.slider-desc {
color: #fff;
text-align: center;
margin: 15px 0 0;
}
.slider {
width: 100%;
height: 100%;
background-color: #000;
}
.headline {
display: table;
width: 100%;
height: 100%;
}
.headline-container {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.headline-container h1, .headline-container p {
background-color: #fff;
}
.controls {
position: absolute;
width: 100%;
bottom: 40px;
text-align: center;
background-color: yellow;
}
最後に、いじりたい場合に備えてフィドルを作成しました。助けてくれてありがとう!