Constrain proportions


I have placed a div that are centered on a page with a given margin, if the window resize i want the div to change in constrain proportions. Is this possible? And how?

The size of div should be 1280x800px. (Ratio 1,6)

The document.getElementById want work...

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>TEST DYNAMIC SWF/DIV</title>
<script type="text/javascript">
       var WindowWidth;
       var WindowHeight;
       var swfHeight;
       var swfWidth;
       var swfHalfHeight;
       var swfRatio;
       var swfMargin;
       // Check window size start
       // ------------------------------------------------------------------------------
       // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
       if (typeof window.innerWidth != 'undefined')
              WindowWidth = window.innerWidth,
              WindowHeight = window.innerHeight
      // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
       else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0)
               WindowWidth = document.documentElement.clientWidth,
               WindowHeight = document.documentElement.clientHeight
       // older versions of IE
               WindowWidth = document.getElementsByTagName('body')[0].clientWidth,
               WindowHeight = document.getElementsByTagName('body')[0].clientHeight
       // ------------------------------------------------------------------------------
       // Check window size end

      // Check flash ratio size start
      // ------------------------------------------------------------------------------  
      // give the flash correct size depend on window width..
      if (WindowWidth>=1681)
            //1920x1200 (1132x800)
            swfWidth = "1280";
            swfHeight = swfWidth / 1.6;
            swfWidth = Math.round(swfWidth);
            swfHeight = Math.round(swfHeight);
            swfHalfHeight = -swfHalfHeight;
            swfHalfHeight = Math.round(swfHalfHeight=swfHeight/2  );
            swfRatio = swfWidth/swfHeight;
            swfMargin = "200";
            //Tilgjengelig plass
            swfWidth = WindowWidth - swfMargin;
            swfHeight = swfWidth / 1.6;
            swfWidth = Math.round(swfWidth);
            swfHeight = Math.round(swfHeight);
            swfHalfHeight = -swfHalfHeight;
            swfHalfHeight = Math.round(swfHalfHeight=swfHeight/2  );
            swfRatio = swfWidth/swfHeight;
      // ------------------------------------------------------------------------------    
      // Check flash size end
      // Update the css style with given value.
      document.getElementById('distance').style.marginBottom = swfHalfHeight;
      document.getElementById('container').style.height = swfHeight;
      document.sgetElementById('container').style.width = swfWidth;

<style type="text/css">
      * {

      html, body {

      body {
            font:100.01%/1.4 sans-serif;
            text-align:center; /* horizontal centering for IE Win quirks */

      #distance {
            margin-bottom:-400px; /* half of container's height */

      #container {
            margin:0 auto;
            position:relative; /* puts container in front of distance */
            border:1px solid #000000;

      #container div {
<style type="text/css">@import("iemac-center.css");</style>

      <div id="distance"></div>
      <div id="container">
            <script type="text/javascript">
            document.write('Vindu bredde er: '+WindowWidth+'<br>');
            document.write('Vindu høyde er: '+WindowHeight+'<br>');
            document.write('Flash bredde er: '+swfWidth+'<br>');                  
            document.write('Flash høyde er: '+swfHeight+'<br>');
            document.write('Flash margin er: '+swfHalfHeight+'<br>');
            document.write('Ratio er: '+swfRatio+'<br>');
            document.write('Margin er: '+swfMargin+'<br>');

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.