title: Why doesn't z-index work?
body: <p>I am writing a web application and I'm having trouble with one part, where I have a rollover thing, but it's currently rolling under. EDIT: pastehtml was rejected, here is jfiddle: <a href="http://jsfiddle.net/XmKwt/1/" rel="nofollow">http://jsfiddle.net/XmKwt/1/</a> </p>
  
  <p>The right div goes under the left div, even though the z-index says it should not.</p>
  
  <p>I have found that if the "position:relative;" css is removed (see source) then it works just fine, but I don't understand why and I need the "position:relative;" css there for other reasons, not demonstrated in this simplified example.</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 xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;script language="javascript" type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;style&gt;
      /* Remove this line and it works */
  
      #featureleft {position:relative;}
  
      /* End */
  
      #layoutdiv { text-align: left; width: 940px; }
      #featureleft { width: 580px; float: left;z-index:10; background:red; }
      #featureright { float: right; z-index:100;}
      #copypaste { background-color: #bbb; margin-bottom: 40px; padding-right: 10px; padding-left: 10px; width: 300px; height:200px; margin-left: 20px; border: solid 5px #000; }
      &lt;/style&gt;
  
      &lt;script language='javascript'&gt;
      $(document).ready(function() {
          $('#copypaste').mouseenter(function(){
              p=$(this).position();
              // increase/move by p.left
              move=Math.round(p.left)-0;
              width=parseInt($(this).css('width'))+parseInt(move);
              margin=0-(parseInt(move)-20);
              inputs=parseInt(move)+280;
              $(this).css('width',width+'px').css('margin-left',margin+'px').css('height',$(this).height);
          });
  
          $('#copypaste').mouseleave(function(){
              $(this).css('width','300px');
              $(this).css('margin-left','20px');
          });
      });
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;div id="layoutdiv" class='container fakewindowcontain'&gt;
          &lt;div id='featurewrapper'&gt;
              &lt;div id='featureleft'&gt;
                  &lt;p&gt;Lorem ipsum dolor sit amet, ut eget et enim, nec auctor habitasse eu mattis eget odio, lacinia vivamus libero dictum, tempor nunc nec nam fringilla mauris, et class dolor curabitur ipsum. Commodo ultricies id&lt;/p&gt;
              &lt;/div&gt;
  
              &lt;div id='featureright'&gt;
                  &lt;div id='copypaste'&gt;
                  &lt;p&gt;Lorem ipsum dolor sit amet, ut eget et enim, nec auctor habitasse eu mattis eget odio, lacinia vivamus libero dictum, tempor nunc nec nam fringilla mauris, et class dolor curabitur ipsum. Commodo ultricies id&lt;/p&gt;
                  &lt;/div&gt;      
              &lt;/div&gt; 
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>