title: jQuery and CSS position element in center of screen
body: <p>The title makes it sound easy, but I guarantee it's not. I have a site at <a href="http://sarahnwatson.com" rel="nofollow">http://sarahnwatson.com</a>. I have modal windows that I have gotten to open by clicking on the tabs About and Contact. The tabs are all in an unordered list that is positioned to the left. The Modal window is coded in directly under the tab that is supposed to open it.</p>
  
  <p>What I can't seem to figure out is how to, between my jQuery code and my CSS code, position the different sized modal windows in the center of the screen. Because they are within an element that is positioned to the left, they try to stay in that element.</p>
  
  <p>Here is the CSS for the tabs and the modal window:</p>
  
  <pre><code>ul.st_navigation{
      position:relative;
      width:100%;
      top:140px;
      left:-300px;
      list-style:none;
  }
  ul.st_navigation li {
      float:left;
      clear:both;
      margin-bottom:8px;
      position:relative;
      width:100%;
  }
  ul.st_navigation li span.st_link{
      background: rgba(0,0,0,.8);
      float:left;
      position:relative;
      line-height:50px;
      padding:0px 20px;
      -moz-box-shadow:0px 0px 2px #000;
      -webkit-box-shadow:0px 0px 2px #000;
      box-shadow:0px 0px 2px #000;
  }
  ul.st_navigation li span.st_arrow_down,
  ul.st_navigation li span.st_arrow_up{
      position:absolute;
      margin-left:20px;
      width:40px;
      height:50px;
      cursor:pointer;
      -moz-box-shadow:0px 0px 2px #000;
      -webkit-box-shadow:0px 0px 2px #000;
      box-shadow:0px 0px 2px #000;
  }
  ul.st_navigation li span.st_arrow_down{
      background: rgba(0,0,0,.8) url(../images/icons/down.png) no-repeat center center;
  }
  ul.st_navigation li span.st_arrow_up{
      background: rgba(0,0,0,.8) url(../images/icons/up.png) no-repeat center center;
  }
  ul.st_navigation li span.st_modal{
      position:absolute;
      margin-left:20px;
      width:40px;
      height:50px;
      cursor:pointer;
      -moz-box-shadow:0px 0px 2px #000;
      -webkit-box-shadow:0px 0px 2px #000;
      box-shadow:0px 0px 2px #000;
      background: rgba(0,0,0,.8) url(../images/icons/modal.png) no-repeat center center;
  }
  </code></pre>
  
  <p>And here is the jQuery:</p>
  
  <pre><code>// Create a modal window
                  function createModal(elm) {
                      var $this = $(this);
                      var $body = $('body');
                      var winHeight = $(window).height();
                      var winWidth = $(window).width();
  
                      $body.prepend('&lt;div id="blackout"&gt;');
                      $("#blackout").fadeIn(1000, function() {
  
                      $(elm).css({ left: '-9999px', display: 'block' });
  
                          var modalHeight = $(elm).height();
                          var modalWidth = $(elm).width();
  
                          var offsetH1 = winHeight/2;
                          var offsetH2 = (winHeight-modalHeight)/2;
                          var offsetW = (winWidth-modalWidth)/2;
  
                          $(elm)
                          .css({ top:offsetH1, left:offsetW, height:'0px' })
                          .animate({ top:offsetH2, height:modalHeight });
  
  
  
                          });
                      });
  
                      });
  
                  }
  
                  $list.find('.st_modal').live('click',function(){
                      var $this = $(this);
                      hideThumbs();
                      $this.closest('li').animate({ left: "0px" }, function() {
                          var $elem = $this.parent().next('div#modal_window');
                          createModal($elem);
                      });
                  });
  </code></pre>
  
  <p>The HTML structure is as follows:</p>
  
  <pre><code>&lt;ul id="st_nav" class="st_navigation"&gt;
                  &lt;li&gt;
                      &lt;span class="st_link"&gt;About&lt;span class="st_modal"&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;div id="modal_window"  style="width:600px;"&gt;
                      &lt;div class="about"&gt;
                          &lt;span class="line"&gt;&lt;span class="left"&gt;Name: &lt;/span&gt;Sarah Watson&lt;/span&gt;
                          &lt;span class="line"&gt;&lt;span class="left"&gt;Age: &lt;/span&gt;16&lt;/span&gt;
                          &lt;span class="line"&gt;&lt;span class="left"&gt;Genre: &lt;/span&gt;Folk, Pop, Alternative&lt;/span&gt;
                          &lt;span class="line"&gt;&lt;span class="left"&gt;Bio: &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
                          I am 16yrs old and an aspiring singer/songwriter. I live in Northern California. My goals and ambitions in life are to someday have a popular song on the radio, whether I am singing it or someone else is. I love to hear just about any kind of music, learning something new is always fun!
                      &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                  &lt;span class="st_link"&gt;Contact&lt;span class="st_modal"&gt;&lt;/span&gt;&lt;/span&gt;
                      &lt;div id="modal_window" style="width: 450px;"&gt;
                          &lt;h2&gt;Contact&lt;/h2&gt;
                          &lt;form id="contact_form" method="POST" action="#"&gt;
                          &lt;label&gt;Name:&lt;/label&gt;&lt;br /&gt;
                          &lt;input type="text" name="name" /&gt;&lt;br /&gt;
                          &lt;label&gt;Email:&lt;/label&gt;&lt;br /&gt;
                          &lt;input type="text" name="email" /&gt;&lt;br /&gt;
                          &lt;label&gt;Reason:&lt;/label&gt; &amp;nbsp;
                          &lt;label&gt;&lt;input type="radio" name="reason" value="praise" checked='checked' /&gt; Praise&lt;/label&gt; &lt;label&gt;&lt;input type="radio" name="reason" value="booking" /&gt; Booking&lt;/label&gt;&lt;br /&gt;
                          &lt;label&gt;Message:&lt;/label&gt;&lt;br /&gt;
                          &lt;textarea name="name"&gt;&lt;/textarea&gt;&lt;br /&gt;
                          &lt;input type="submit" value="Submit" name="submit" /&gt; &lt;span class="status_message"&gt;&lt;/span&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
  </code></pre>