FireFox Logo

Setting a Minimum Height to a Div or HTML element in ALL BROWSERS.



So you wanna set a minimum height on a Div tag that works in all browsers ehh? Well no need to worry. Here is the easy way to do it and it works in all browsers.


Share

First things first. Use the "min-height" in your css like this:

.myDiver{
     min-height:100px;
}

NEXT! Set the regular height to "auto" using the "!important" tag.

.myDiver{
     min-height:100px;
     height:auto !important;
}

LAST! Set the regular height (again) but to the minimum height. ;-)

.myDiver{
     min-height:100px;
     height:auto !important;
     height:100px;
}

This will keep the div at 100px; and if the content inside of it extends beyond 100px, it will grow. This is true in ALL BROWSERS! Check out this example below:

sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd
sdf ffdsa fd

COMMENTS:





This has been bugging me for years - I finally decided to check out Google for a firm solution. Many thanks!
Benjamin at Mar 12th - 7:05pm
Hi,

Wonderful tip! Thanks.
Chandrasekarn at Mar 9th - 10:54am
Dosnt work if you have backgroundcolor
Daniel at Mar 3rd - 5:33am
Thank you very much! Very cool :-)
Kathy at Feb 15th - 6:13am
you are amazing. thank you so damn much!
bronwyn at Feb 10th - 9:33am
Superb! Thank you. This was beyond me... until now! :-)
ABC4FREE.com at Feb 3rd - 1:17pm
Hey... I just want to say that this was a VERY nice solution. Great JOB! Works PERFECT!
Matt at Jan 29th - 12:48pm
WOW now this has made my live very easy. Than you so so much.
Gremlin1708 at Jan 28th - 9:49am
People like you inspire people like me to aspire to donate like you have when we know more.
Thank you.
Jeremy at Jan 25th - 4:54pm
I love you man

CSS adoption is stupid if it's not sepcifed then it has to be auto, that's what anyone would think!!
aaaa at Jan 25th - 11:17am
Thanks! This is just what I was looking for and it works great.
Jay at Jan 17th - 1:46pm
a
a at Jan 3rd - 8:33am
TNX!
nikolas, israel at Dec 7th - 3:52am
great thanks a lot!!!!1
horace at Nov 26th - 9:50pm
Worked for us :) Thanks very much.
Vilius at Oct 30th - 1:11pm
Really a cool trick buddy.....thanx a lot.....keep going.
Raj..... at Oct 26th - 9:55am
Thanks man !
Kevin at Oct 24th - 7:24am
I figured it out -- the template I'm using set the overflow: hidden in the CSS for IE6 -- had to reset it to overflow: visible and now it works fine.

~Graham
Graham Strong at Oct 6th - 11:25am
Never mind -- works if the page is longer than the minimum height, but not if it's shorter. Hmm...

~Graham
Graham Strong at Oct 6th - 10:49am
thanks a lot mate
sparkcomputing.co.uk at Sep 22nd - 6:14am
Superb.. simple and platform independent code.
Thanks!!
Ashish Gujalwar at Sep 18th - 5:56am
Excellent, quick, and very useful! Cheers!
Bully at Sep 15th - 2:02pm
%u0644%u0642%u062F %u0643%u0646%u062A %u0641%u064A %u0627%u0644%u062D%u0627%u062C%u0629 %u0625%u0644%u064A%u0647
%u0634%u0643%u0631%u0627
أبÙÙØ§Ø±Ø³ at Sep 11th - 6:40am
love it - but then it breaks the ability to handle width: 100% or min-width: 1150px; to make a background image scale...

adam at Sep 8th - 12:33pm
Nice tip- thanks
Bill at Aug 29th - 10:38pm
Nice tip- thanks
Bill at Aug 29th - 10:38pm
wow, don't know why that works but it does the trick - thanks!
thebigkrumm at Aug 25th - 8:56pm
Thanks dude.. really cool
ekS at Aug 23rd - 12:23am
Thanks very much...so easy
Phil at Aug 14th - 11:41am
Thanks very much...so easy
Phil at Aug 14th - 11:35am
Can't thank you enough.
justy at Aug 6th - 5:37pm
Thanks alot its works great across all browsers.
Neven at Aug 6th - 6:00am
That was simple and concise, and did exactly what it was supposed to do. Thank you so much!
Jesse at Aug 5th - 12:47pm
a beer for you my friend...
HereForTheBeer at Jul 29th - 8:44am
Really good Thanks
chintz at Jul 27th - 4:42pm
Really good Thanks
chintz at Jul 27th - 4:42pm
beaut!
thankful at Jul 24th - 9:56am
This is a freakin' flex! Thanks.
mlima at Jun 30th - 1:47am
Thanks!
Romek at Jun 24th - 7:51am
This is beautiful. I read so much BS about how complicated it was to do this. Thank you!
Alan at Jun 17th - 10:27pm
The ducks nuts
imatool at May 28th - 2:39pm
Thanks!!
Mohit at May 16th - 4:03am
Thanks Man, Works Great! :-*
Ghasem at May 3rd - 8:36am
Exactly what i was after cheers
Chris at May 2nd - 9:34am
Thank you! that worked like a charm
Anthony at Apr 24th - 3:47pm
Awsome, very simple and cross browser.

Thanks
Colin at Apr 14th - 11:29am
Thanks so much! Very timely find for me.
Ilene at Apr 10th - 10:42pm
Thanx...it works nice...
Sudhir at Apr 10th - 4:27am
awesome!
kevin at Apr 2nd - 10:12pm
Does this work with images as I can't see to get it to work
Graham at Mar 22nd - 2:41pm
You are awesome... works like a charm!
Mick at Mar 19th - 2:07pm
Great hack!
Thanks for sharing!
Jaime Carrion at Mar 4th - 3:28am
Perfect. Thanks.
Someone at Jan 25th - 12:09pm
Thanks!
akidur at Jan 23rd - 10:13am
amazing. thank you
zi at Jan 13th - 3:47am
great, I'm happy the answer to my trouble is so simple
it works, thank you :D
Takumi at Jan 7th - 2:47pm
wow great thank u dude
basker at Dec 20th - 7:06am
Thank you sooooooooo much.
Crazyguy at Dec 20th - 7:06am
Thanx this is very userfull
Nishant at Dec 16th - 2:03am
thank you.... tat was much needed help :)
shashi at Nov 24th - 11:36pm
Great Thanks
Kaarthik at Nov 14th - 3:42am
Wonderful. Works great. Many thanks.
TSinnott at Nov 5th - 8:26pm
Thanks!
Shashikant at Oct 6th - 1:02am
Works Grrrrreat! Thanks very much :o)
gd at Oct 5th - 11:15am
This is jus what I've been looking for. Thanks a billion!
QC at Jul 30th - 7:06am
Excellent, thanks for this!
Easy-E at Jul 2nd - 11:13am
cool banana!
ty at Jun 25th - 12:44am