Is it ok yet to use this? How do I bullet proof it for older browsers?
height: -moz-calc(100% - 70px);
height: -webkit-calc(100% - 70px);
height: calc(100% - 70px);
Here is specifically what I'm trying to accomplish.
- A Full Width / Fixed Height Header
- A Slider that stretches full width and full height - minus the height of the header.
- A headline block that is centered vertically and horizontally in the slider
- A Controls block that is always a fixed height from the bottom of the slider
Here's an image of what I have been able to achieve so far. It's ALMOST perfect, except for the part in bold above. The slider (black area) currently stretches 100% height and flows behind the header, which isn't ok for images.
If I add padding or margin, it extends the slider height beyond 100% and I get a scrollbar. Using the height calculation above seems to fix it, but from my understanding, calc()
isn't compatible with IE 7, IE 8, iOS 5 or lower, or Android.
Is there a better fix for this problem? jQuery is ok, but I'd prefer a CSS solution if one exists.
Here's my 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>
Here's my 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;
}
Finally, I made a fiddle in case you want to play around with it. Thanks for the help!