I have a short intro text inside a box, if the user wants to read futrher he can toggle a hidden div element that shows the rest of the content. Under this intro box I have some other element, which I always want to stay in that position. I want the toggled text to 'show above' the fixed content, and I don't want it to push downwards when the toggled div is opened. I've experimented with various z-index values, absolute and relative positioning, to no avail. Is there a clean CSS based solution to this? Please help! Here's a demo of what I'm trying to do:
> <!DOCTYPE html PUBLIC "-//W3C//DTD
> XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html
> xmlns="http://www.w3.org/1999/xhtml"
> xml:lang="en"> <head> <style
> type="text/css"> .container{width:
> 400px;
> height: 500px;
> border: 1px dashed #999;
> } div.container{padding:0; margin:0} #morecontent{
> z-index: 100
> } #morecontent,.introcontent{background: #DFFAFF;} div#fixedcontent{background:
> #FFDFDF;
> z-index: -1;
> position: absolute;
> width: 400px
> } </style> <title>Toggle overlap - test</title> </head> <body>
> <div class="container"> <div id="">
> <script type="text/javascript">
> function toggle(obj){
> var el=document.getElementById('morecontent');
> if (el.style.display !='none'){
> el.style.display='none';
> }
> else {el.style.display='';
> }
> }
> </script>
> <p class="introcontent">Lorem ipsum dolor sit amet, consectetur
> adipiscing elit. Aenean in pede congue
> ipsum sollicitudin pellentesque. Nunc
> t tortor dolor, sagittis nec, placerat
> vel, commodo sed, nunc. Vivamus
> bibendum molestie orci. Duis nec leo
> at libero fermentum molestie. Nam eu
> risus.<br />
> There's more if you press toggle...
>
> </p>
> <a href="JavaScript: toggle(this)">Toggle</a>
> <div id="morecontent" style="display:none;">
> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in
> pede congue ipsum sollicitudin
> pellentesque. Nunc t tortor dolor,
> sagittis nec, placerat vel, commodo
> sed, nunc. Vivamus bibendum molestie
> orci. Duis nec leo at libero fermentum
> molestie. Nam eu risus.
> </p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
> Aenean in pede congue ipsum
> sollicitudin pellentesque. Nunc
> t tortor dolor, sagittis nec, placerat
> vel, commodo sed, nunc. Vivamus
> bibendum molestie orci. Duis nec leo
> at libero fermentum molestie. Nam eu
> risus.
> </p>
> </div>
>
> <div id="fixedcontent">
> <p>This should stay 'under' the toggled content!</p>
> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in
> pede congue ipsum sollicitudin
> pellentesque. Nunc t tortor dolor,
> sagittis nec, placerat vel, commodo
> sed, nunc. Vivamus bibendum molestie
> orci. Duis nec leo at libero fermentum
> molestie. Nam eu risus.
> </p><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
> Aenean in pede congue ipsum
> sollicitudin pellentesque. Nunc
> t tortor dolor, sagittis nec, placerat
> vel, commodo sed, nunc. Vivamus
> bibendum molestie orci. Duis nec leo
> at libero fermentum molestie. Nam eu
> risus.
> </p>
> </div> </div> </div> </body> </html>