1

In my website, I want the body tag to have a minimum width of 640px. Thing is, IE6 doesn't recognize min-width, so I'm trying to fix this with a CSS expression in my IE6 stylesheet:

body {
    width : expression(this.clientWidth < 639 ? "640px" : "auto");
}

But this is crashing the browser as son as I resize it. I've tried with document.body.clientWidth instead of this.clientWidth but it too crashes. Is it possible to fix this?

Knu
  • 14,806
  • 5
  • 56
  • 89
federico-t
  • 12,014
  • 19
  • 67
  • 111
  • IE6 supports CSS expressions? I have never heard of this. Is there a plugin involved you're not telling us about... or is this actually some amazing IE6 feature? – Ry- May 02 '12 at 23:33
  • IE6 does support CSS expressions. I would avoid them. This S.O. answer may help you, John Doe: http://stackoverflow.com/questions/93274/min-width-in-msie-6 – kinakuta May 02 '12 at 23:44
  • Thanks guys, I've tried many ways to do this but the only one which actually worked when I tried it was [this one](http://stackoverflow.com/questions/93274/min-width-in-msie-6#93530). It's a bit HTML invasive, but it's a multibrowser fix – federico-t May 05 '12 at 11:14

1 Answers1

2

If the body has padding:0, then this should work:

body {
    width : expression(this.clientWidth < 641 ? "640px" : "auto");
}

Demo: http://jsfiddle.net/kt2m8/embedded/result/


In case there is some padding you could use something like this:
body {
    width : expression(this.clientWidth < 641+parseInt(document.body.currentStyle.paddingLeft,10)+parseInt(document.body.currentStyle.paddingRight,10) ? "640px" : "auto");
}

Demo with padding:10px and margin:10px: http://jsfiddle.net/vL689/embedded/result/

stewe
  • 41,820
  • 13
  • 79
  • 75
  • Tried it and it didn't work :/. I couldn't even see the example in jsfiddle using ie6, lol. Thanks for your answer anyways – federico-t May 05 '12 at 11:16
  • @JohnDoe: I tried it in IE6 (6.00.2900.2180) with Security settings: Medium -> http://i.stack.imgur.com/HUBKx.jpg, i hope this helps. – stewe May 05 '12 at 11:26