Home  »  Code Snippets  »  HTML  »

How to set Min/Max-Height and Min/Max-Width for IE and for all other browser?

 Posted By : Manoranjan SahooPosted Date : 19/08/2011 02:34:07 PM Category : HTML Points : 4

We can set min-height or max-height, min-width or max-width for standards-compliant browsers except IE. To set min/max-height or min/max-width for IE we have to use expression attribute of CSS property. The CSS expression attribute enables JavaScript commands to be executed within Internet Explorer. Internet Explorer completely fails to understand the max-width attribute. But IE supports its own expression attribute, which enables us to use JavaScript expressions to manipulate XHTML document properties such as max-width and max-height.

max-height :
We can set max-height in all standard-compliant browsers except IE with below code :


.classname{max-height:100px;}

But in case of IE we need to use expression attribute to achieve this goal. Follow below code :

.classname{height: expression( this.scrollHeight > 99 ? "100px" : "auto" );}

above code will set the max-height for this class to 100px in IE browser.

min-height :
We can set min-height in all standard-compliant browsers except IE with below code :

.classname{min-height:100px;}

But in case of IE we need to use expression attribute to achieve this goal. Follow below code :

.classname{height: expression( this.scrollHeight < 99 ? "100px" : "auto" );}

above code will set the min-height for this class to 100px in IE browser.

max-width :
We can set max-width in all standard-compliant browsers except IE with below code :

.classname{max-width:400px;}

But in case of IE we need to use expression attribute to achieve this goal. Follow below code :

.classname{width: expression( document.body.clientWidth > 399 ? "400px" : "auto" );}

above code will set the max-width for this class to 400px in IE browser.

min-width :
We can set min-width in all standard-compliant browsers except IE with below code :

.classname{min-width:400px;}

But in case of IE we need to use expression attribute to achieve this goal. Follow below code :

.classname{width: expression( document.body.clientWidth < 399 ? "400px" : "auto" );}

above code will set the min-width for this class to 400px in IE browser.

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.