title: Proportionally scale image on window resize
body: <p>I have a demo here to illustrate my problem</p>
  
  <p><a href="http://www.ttmt.org.uk/forum/gallery1/" rel="nofollow">http://www.ttmt.org.uk/forum/gallery1/</a></p>
  
  <p>It's a simple list of images at scrolls across the page.</p>
  
  <p>When the image is clicked a larger image appears above it, lightbox style.</p>
  
  <p>I want the height of this image to be a percentage of the height of the window (85%) and the width to adjust proportionally.</p>
  
  <p>If the window is resized I would like the image to scale proportionally.</p>
  
  <p>In Safari the large image appears at the correct height and scales proportionally when the height is changed but doesn't scale correctly when the width is changed less then the width of the image.</p>
  
  <p>In Firefox the large image doesn't appear at the correct height and doesn't scale when the height is changed but it does scale proportionally when the width is changed.</p>
  
  <p>How do I get the image to appear at the correct height and scale proportionally across browsers.</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html&gt;
        &lt;head&gt;
        &lt;title&gt;Title of the document&lt;/title&gt;
  
        &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"&gt;&lt;/script&gt;
        &lt;link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset-min.css"&gt;
  
        &lt;style type="text/css"&gt;
          ul#gallery {
              margin:100px 0 0 0;
  
              float:left;
              height:500px;
              margin-right:-20000px;
          }
          ul#gallery li{
            display:inline;
          }
          ul#gallery li img{
            float:left;
            height:100%;
          }
          #header{
            position:fixed;
            margin:20px 0 0 20px;
          }
          #header img,
          #header ul#info{
            float:left;
          }
          #header ul#info{
            margin:5px 0 0 50px;
          }
          #header ul#info li{
            color:#aaa;
            font:.95em/1.5em Helvetica, sans-serif;
          }
          #header ul#info li a{
            color:#aaa;
            text-decoration:none;
          }
          #header ul#info li a:hover{
            color:#333;
          }
          #header select{
            margin:20px 0 0 50px;
          }
          #lightbox {
                  position:fixed; 
                  top:0; 
                  left:0; 
                  width:100%; 
                  height:100%; 
                  background:url(overlay.png) repeat; 
                  text-align:center;
              }
              #lightbox p {
                  text-align:right; 
                  color:#fff; 
                  margin-right:20px; 
                  font-size:12px; 
              }
              #lightbox img {
                  box-shadow:0 0 15px #111;
                  -webkit-box-shadow:0 0 15px #111;
                  -moz-box-shadow:0 0 15px #111;
                  max-width:940px;
              }
              #content img{
                height:85%;
                max-width:100%;
              }
        &lt;/style&gt;
  
        &lt;/head&gt;
  
      &lt;body&gt;
  
        &lt;ul id="gallery"&gt;
          &lt;li&gt;&lt;a href="images/01.jpg" class="lightbox_trigger"&gt;&lt;img src="images/01.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/02.jpg" class="lightbox_trigger"&gt;&lt;img src="images/02.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/03.jpg" class="lightbox_trigger"&gt;&lt;img src="images/03.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/04.jpg" class="lightbox_trigger"&gt;&lt;img src="images/04.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/05.jpg" class="lightbox_trigger"&gt;&lt;img src="images/05.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/06.jpg" class="lightbox_trigger"&gt;&lt;img src="images/06.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/07.jpg" class="lightbox_trigger"&gt;&lt;img src="images/07.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/08.jpg" class="lightbox_trigger"&gt;&lt;img src="images/08.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/09.jpg" class="lightbox_trigger"&gt;&lt;img src="images/09.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/10.jpg" class="lightbox_trigger"&gt;&lt;img src="images/10.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/11.jpg" class="lightbox_trigger"&gt;&lt;img src="images/11.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/12.jpg" class="lightbox_trigger"&gt;&lt;img src="images/12.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/13.jpg" class="lightbox_trigger"&gt;&lt;img src="images/13.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/14.jpg" class="lightbox_trigger"&gt;&lt;img src="images/14.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="images/15.jpg" class="lightbox_trigger"&gt;&lt;img src="images/15.jpg" /&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
  
  
      &lt;script&gt;
        jQuery(document).ready(function($) {
  
          $('.lightbox_trigger').click(function(e) {
  
              e.preventDefault();
  
              var image_href = $(this).attr("href");
  
              if ($('#lightbox').length &gt; 0) { // #lightbox exists
  
                  $('#content').html('&lt;img src="' + image_href + '" /&gt;');
  
                  //$('#lightbox').show();
  
                  $('#lightbox').fadeIn('2000');
              }
  
              else { 
  
                  var lightbox = 
                  '&lt;div id="lightbox"&gt;' +
                      '&lt;p&gt;Click to close&lt;/p&gt;' +
                      '&lt;div id="content"&gt;' + 
                          '&lt;img src="' + image_href +'" /&gt;' +
                      '&lt;/div&gt;' +  
                  '&lt;/div&gt;';
  
                  $('body').append(lightbox);
              }
  
          });
  
          $('#lightbox').live('click', function() { 
              $('#lightbox').hide();
          });
  
        });
        &lt;/script&gt;
      &lt;/body&gt;
  
      &lt;/html&gt;
  </code></pre>