With most sites I build, I would have quite a big use for min-height but with not all browsers supporting it, I can’t really use it. So today I had a bash using jQuery to solve this dilemma, and here’s what I came up with.

First I defined my minimum height for my element in a var called minHeight. Then defined the height of the element (that I wanted to apply the minimum height to) as the page was loading into actualHeight using jQuery’s height() function to obtain the value.

Then using an if statement I basically said, if the height of my div is smaller than my minimum height, apply the minimum height to it’s CSS property.

Give it a whirl! Comment below with any problems or where you’ve used it.

$(document).ready(function(){
 
	var minHeight = 540;
 
	var actualHeight = $('#div-name').height();
 
	if (actualHeight < minHeight){
 
		$('#div-name').css({'height' : minHeight});
 
	};			
 
});

Author: Benjamin Reid

My name is Benjamin Reid, I live in the UK and keep the magic locked into this site.

RSS Icon

Subscribe to the RSS feed some design goodness, get in on the upcoming software give-aways!

Digg Icon Share Quick Tip #1 - Getting min-height to work in all browsers using jQuery (JavaScript) to Twitter Share Quick Tip #1 - Getting min-height to work in all browsers using jQuery (JavaScript) to Delicious Share Quick Tip #1 - Getting min-height to work in all browsers using jQuery (JavaScript) to Facebook

Related post(s)

Comments left by other wizards

7 Responses | Make a comment

Leave your words of wisdom

Leave a Reply

This is a Gravatar

Your name