We Recommend

CSS: The Definitive Guide CSS: The Definitive Guide
Provides you with a comprehensive guide to CSS implementation, along with a thorough review of all aspects of CSS 2.1. Updated to cover Internet Explorer 7, Microsoft's vastly improved browser, this new edition includes content on positioning, text wrapping (nowrap), lists and generated content, table layout, user interface, paged media, and more.


Posted By

jonhenshaw on 12/31/69


Tagged

fix css ie minheight


Versions (?)


Who likes this?

202 people have marked this snippet as a favorite


tylerhall
daniel
Roshambo
luxuryluke
jamesmcoats
designerd
talaris
rdmey
samuraicoder
sendoa
panatlantica
dertimbo
kgosser
fatihturan
millisami
markfavazza
px
hxseven
zensir
imbuez
oronm
ttscoff
visualAesthetic
kemo
Hirmine
block
dmarten
basicmagic
noname
Sahoglu
clapfouine
tavo
noah
KilgoreTrout67
miyazima
icarus
nankoweap
shellydennison
lamy
cmslounge
duandan
cynic68
joseluis
Mikker
hollowmyth
manub
m10
fael
robotoverlord
rich13
marcoba
marcio
asimovi
SamuelMiller
aziz
jorgenskogmo
cubit
hariharank12
udayrayala
b00gertoad
m-alo
gasface
saiko
sjaq
kgl
Mithun
Winkyboy
torkil
jfherring
celoria
sp1r1t
adix
willgarrison
kaiser79
noebarnabas
visuallyspun
tome2k
KurveMedia
lzyy
axoplasm
SpinZ
snucko
seekup00
ernscht
ido
usgraphicscom
stphnclysmth
sosof
Wizzle
wbowers
danbair
mb
zeljkoprsa
rovision
jamescrossett
digitalifer
llexa
sleggat
stylz
alvaroisorna
ischenkodv
mmccrack
Arzakon
b0li
tomdebruin
crisb
remix4
enajenkins
nijitaro
vince2doom
fsorbello
heinz1959
pablodgavilan
jamesming
nickdoherty
esquareda
picale
jonhenshaw
superdeluxesam
titox
shaho
Leech
l1r
wilburhimself
higrade
grassdog
Wiederkehr
rubensarrio
jero
sulfurito
jimmysessions
SnipItPrpDemo
ahjo
chippper
asturi
rareyman
matoilic
bambam
ginoplusio
moonbather
Sn0opy
loyst
salibaray
luggnagger
redstorm
VaiT
dviero
johnleestudio
peonhunter
baqc
fruehjahr
ilumin
aleprieto
gerhardsletten
wordGeek
LostCore
dong4138
francesL
justinscheetz
jder
Hilyin
shalva
rwczippy
tobiasmay
yuindustries
hdragomir
vevhlos
elbuenob
ntulip
jrharshath
Twain
bryandease
bsw1971
owais
bpdp
endorfin
Anber
ss44
cschlens
powareverb
geothen
nreliu
hamiltonmascioli
delikassap
LordBumpet
bigheadlyf
johnloy
Triconium
ikimozu
nickBarker
g0mer
delarge
fsn
fragmentist
nightowl
darkapple
nb109
exanimo9
jpsirois
Hollow
lilumi


min-height for IE (and all other browsers)


Published in: CSS 


URL: http://www.cssplay.co.uk/boxes/minheight.html

Since min-height doesn't work in IE, this code makes up for IE's shortcomings. The first part of the code is the correct code that works in Firefox and Safari. The second part of the code is for IE. Internet Explorer will ignore min-height and is just given a height of 8em. The IE bug automatically expands the container to fit the extra text.

  1. /* for browsers that don't suck */
  2. .container {
  3. min-height:8em;
  4. height:auto !important;
  5. }
  6.  
  7. /* for Internet Explorer */
  8. /*\*/
  9. * html .container {
  10. height: 8em;
  11. }
  12. /**/

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: jonhenshaw on July 23, 2006

I wanted to make it clear that the the 8em is arbitrary and can be whatever height you would like it to be.

Posted By: Winkyboy on January 14, 2008

You don't really need the "* html" part of the IE definition, I think. This same solution can be found on DustinDiaz's site (http://www.dustindiaz.com/min-height-fast-hack/) without it. Example:

selector { min-height:500px; height:auto !important; height:500px; }

Posted By: rasmus on April 4, 2008

If you don't mind the undercore hack you can do it even shorter:

selector { min-height: 500px; _height: 500px; }

This way you avoid using !important for compliant browsers which may or may not trip you up later down the line (through css or style set through js).

Posted By: superdeluxesam on September 10, 2008

Is this specifically IE6 and lower? From my (admittedly brief) look through google it seems IE7 supports the property.

Posted By: Pring4 on November 10, 2008

This is specifically for IE6. It does not fully support IE5.5 and below. And yes, IE7 does support min-height properly.

Posted By: bambam on November 20, 2008

Only works for me (in IE7) if I put an !important on the 2nd section:

/* for browsers that don't suck */ .container { min-height:8em; height:auto !important; }

/* for Internet Explorer / /*/ * html .container { height: 8em !important; } /**/

Posted By: mihael on January 26, 2009

this could also be shortend like this:

container {

height:auto!important; mih-height:300px; height:300px: /for IE6/ }

Posted By: jaspertandy on April 13, 2009

yeah, those could go in the same declaration, as IE6 doesn't support !important or min-height so no hacks are required to get it to ignore those attributes. IE7 (to the best of my experience) supports !important and min-height so you're safe to use it there.

Posted By: joles04 on April 16, 2009

Joel Larios

Posted By: webdevelopertut on June 29, 2009

http://htmlcsstutorials.blogspot.com/2009/06/how-to-have-div-min-height.html

This tutorial will tell you how to give min-height, which will work in all the browsers including ie6

Posted By: webdevelopertut on June 29, 2009

http://htmlcsstutorials.blogspot.com/2009/06/how-to-have-div-min-height.html

This tutorial will tell you how to give min-height, which will work in all the browsers including ie6

You need to login to post a comment.