Entries filed under CSS

Better “max-width” workaround for IE 6

IE 6 famously lacks support for CSS 2.1′s max-width and max-height properties. Most solutions involve an IE 6-exclusive expression(…) with an inline conditional:

max-width: 100px;
width: expression(this.clientWidth > 102 ? "100px" : "auto");

Despite the apparent success of this technique, I’ve still found the inline conditional to be intermittently problematic. A slightly different take on the same solution has worked better for me:

max-width: 100px;
width: expression(Math.min(this.clientWidth, 100) + "px");

Shorter, and IMO, marginally more elegant… if any IE hack could bear that label.