title: Set max-width in Internet Explorer
body: <p>What I need is to set the limit of an image's width to 100% in Internet Explorer, like other browsers do with <code>max-width</code>.  That is, if the image's width is larger than the containing area's width, it scales down to fit the width of the containing area, but if it's smaller, its size doesn't change. Similarly, if the image is inside a table cell (<code>td</code>) and it's larger than the cell, I want it to scale to the size of the cell, instead of expanding it.</p>
  
  <p>While there are other questions and answers that seem to be about this, I can't get any of them to work.  For example, this solution is usually suggested to emulate max-width in Internet Explorer:</p>
  
  <p><a href="http://www.svendtofte.com/code/max_width_in_ie/" rel="noreferrer">http://www.svendtofte.com/code/max_width_in_ie/</a></p>
  
  <p>In essence using this:</p>
  
  <pre><code>width:expression( 
      document.body.clientWidth &gt; (500/12) * 
      parseInt(document.body.currentStyle.fontSize)?
          "30em":
          "auto" );
  }
  </code></pre>
  
  <p>However, when I try it I don't get expected results at all. In some cases I get width values of -1 and no displayed image at all when I check in Firebug or something like it.</p>
  
  <p>And I don't see how that solution could work either.</p>
  
  <p>EDIT:</p>
  
  <p>According to request, here is some sample code:</p>
  
  <pre><code>&lt;table cellpadding="4" cellspacing="0"
      summary="" id="Push12Matt__simpletable_rph_vch_32" border="0" class="simpletable"&gt;
      &lt;tr class="strow"&gt;
       &lt;td valign="top" class="stentry" width="50%"&gt;
        &lt;div class="fig fignone" id="Push12Matt__fig_6a268fd9-2a26-474f-83f5-528ffbab70d3"&gt;&lt;a
          name="Push12Matt__fig_6a268fd9-2a26-474f-83f5-528ffbab70d3"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;p class="figcap"
          &gt;Bild 1. Uponor Push 12&lt;/p&gt;
         &lt;a name="Push12Matt__image_4dd4d9ef-f95c-41f1-b423-7ddd3a2b0c06"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;img
          class="image" id="Push12Matt__image_4dd4d9ef-f95c-41f1-b423-7ddd3a2b0c06"
          src="/handbok/images/Push12/Push12_byggmatt.jpg" /&gt;
        &lt;/div&gt;
       &lt;/td&gt;
  
       &lt;td valign="top" class="stentry" width="50%"&gt;
        &lt;div class="fig fignone" id="Push12Matt__fig_689a2b08-ffbb-4f92-9a27-010e99665959"&gt;&lt;a
          name="Push12Matt__fig_689a2b08-ffbb-4f92-9a27-010e99665959"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;p class="figcap"
          &gt;Bild 2. Uponor ElPush 12&lt;/p&gt;
         &lt;a name="Push12Matt__image_f6d7c2fa-8ab3-4e46-b79c-e7881dff03e9"&gt;&lt;!-- --&gt;&lt;/a&gt;&lt;img
          class="image" id="Push12Matt__image_f6d7c2fa-8ab3-4e46-b79c-e7881dff03e9"
          src="/handbok/images/Push12/Push12Electronic_byggmatt.jpg" /&gt;
        &lt;/div&gt;
       &lt;/td&gt;
  
      &lt;/tr&gt;
     &lt;/table&gt;
  </code></pre>
  
  <p>And the simple css (working for all browsers except IE):</p>
  
  <pre><code>img
  {
      max-width : 100%;
      max-height : 100%;
  }
  </code></pre>
  
  <p>But it doesn't work for this code in IE. Maybe it has something to do with the fact that it is placed in a table, I don't know, but when I try this div example on W3Schools, it works fine:
  <a href="http://www.w3schools.com/cssref/playit.asp?filename=playcss_max-width&amp;preval=50%25" rel="noreferrer">http://www.w3schools.com/cssref/playit.asp?filename=playcss_max-width&amp;preval=50%25</a></p>
  
  <p>EDIT 2:</p>
  
  <p>Example full HTML page:</p>
  
  <pre><code>&lt;!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html lang="sv-se" xml:lang="sv-se"&gt;
      &lt;head&gt;
          &lt;title&gt;Image test&lt;/title&gt;
  
          &lt;style type="text/css"&gt;
              body {
                  max-height : 100%;
                  max-width : 100%;
                  width : 500px;
  
  
              }
              img {
                  max-height : 100%;
                  max-width : 100%;
                  width : auto;
                  height : auto;
              }
              td
              {
                  max-height : 100%;
                  max-width : 500px;
                  display : block;
              }&lt;/style&gt;
      &lt;/head&gt;
      &lt;body id="frontpage"&gt;
          &lt;h1 class="title topictitle1"&gt;Image test&lt;/h1&gt;
          &lt;div class="body conbody"&gt;
              &lt;table&gt;
                  &lt;tbody&gt;
                      &lt;tr&gt;
                          &lt;td&gt;
                              &lt;img src="Push12_byggmatt.jpg" /&gt;
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;img src="Push12Electronic_byggmatt.jpg" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This page shows the same problem. The images do not scale down to fit in the table cells. In other browsers I can resize the window as much as I want, and the images just keeps scaling down. IE8 and 9 don't. So it seems IE8 and 9 support max-width and max-height, but only for pixel values, not for percentage values - i.e. it only has partial support... If I'm correct, I'm really surprised it's so hard to find any info on this on the Internet. Everyone's just talking about these browsers as finally supporting it after IE6 didn't...</p>
  
  <p>Anyway, I have written a jQuery workaround, but I would rather have not needed it. So if anyone can tell me I'm wrong and show me that IE8 and 9 actually do support max-width percentage values I'd be glad to be wrong :-)</p>