Min-height in Safari Hack

Aug 5 2004

When coding CSS layouts, min-height is often useful to have around. Unfortunately, it’s not widely supported among browsers (other than Mozilla, natch). (For those not familiar with it, min-height defines a minimum height on an element.) And, generally speaking you can simply make use of min-height (for real browsers) along with height for IE — which essentially treats height like min-height, as it happily busts out of its container if there’s more content than the allotted height.

The tricky part? Safari. If you need to support it, you’ll find that it supports neither min-height nor IE’s pretend min-height. (In fairness to Safari, the code for min-height has been implemented, but the current Safari release doesn’t yet incorporate that.) Fortunately, there is a workaround. Anne van Kesteren discovered that you can make use of the intrinsic nature of display:table-cell to get the same effect in Safari. And, Vinnie Garcia has a good write-up on the technique.

Really, it’s an extension of the old IE-pretend-min-height idea. A regular height is defined and then that element is further set to display:table-cell — and since table cells automatically expand as needed, Safari in effect gets a min-height property.

div
{

display: table-cell;
height: 200px;

}

The only downside is that, while IE/Windows ignores display:table-cell, IE/Mac goes a bit nuts. But, that can be worked around by using the star-HTML hack which can be used to feed separate CSS to IE (both Mac & Windows). So, the complete min-height set of properties (supporting Mozilla, IE/Windows, IE/Mac and Safari) could look something like this:

div
{

display: table-cell;
height: 200px;

}

* html div
{

display: block;

}

4 Comments to “Min-height in Safari Hack”

  1. I have a better solution….check out my new Safari Hack:

    http://www.stormdetector.com/hacks/safarihack.html

    By Mitchell on October 28th, 2004 at 12:24 pm
  2. Mitchell,
    Your hack is unreliable. Try out this one instead.
    http://www.mausonio.com/?p=31

    By Matthew on July 4th, 2007 at 11:35 am
  3. thanks for the GREAT post! Very useful…

    By Whatever-ishere on November 21st, 2007 at 12:26 pm
  4. If you guys want a revised Safari CSS Hack using the Safari Stokely Hack, check out my web page here: http://www.stormdetector.com/hacks/InternetExplorer7Hack.html

    Ive modified the complete Stokely Hack for CSS so you can target IE5,IE6,IE7,Firefox,and all versions of Safari in one hack and isolate each!

    By Stormy on February 16th, 2008 at 12:29 am

Leave a Reply