Posts about the Java and IDE universe…

Menu

Sometimes there are special requirements for the width restrictions of a website. For example the width of the panel has to be at least 100px, but should not exceed 800px.

The first approach is to use the CSS attributes min-width/max-width. But these will not work in MS Internet Explorer. There are several IE6-workarounds like using Javascript-based CSS-expression, but i think those are ugly.

The following approach uses easy Javascript scripting: Calculate the width using jQuery, compare it to the reference width and set it to the min-/max-value if needed.

Simple usage:

setMinMaxWidth(100,800, 'myDivID');

This code also can easily be adapted for min-/max-height.

Note: You cannot get the width of an invisible element. So you have to make the element visible before invoking the methods.