Note that there are some explanatory texts on larger screens.

plurals
  1. POI want a toggling div elemenet, to overlap the underlaying content with z-index. How can I achieve this?
    primarykey
    data
    text
    <p>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:</p> <pre><code>&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD &gt; XHTML 1.0 Transitional//EN" &gt; "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &gt; &lt;html &gt; xmlns="http://www.w3.org/1999/xhtml" &gt; xml:lang="en"&gt; &lt;head&gt; &lt;style &gt; type="text/css"&gt; .container{width: &gt; 400px; &gt; height: 500px; &gt; border: 1px dashed #999; &gt; } div.container{padding:0; margin:0} #morecontent{ &gt; z-index: 100 &gt; } #morecontent,.introcontent{background: #DFFAFF;} div#fixedcontent{background: &gt; #FFDFDF; &gt; z-index: -1; &gt; position: absolute; &gt; width: 400px &gt; } &lt;/style&gt; &lt;title&gt;Toggle overlap - test&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &gt; &lt;div class="container"&gt; &lt;div id=""&gt; &gt; &lt;script type="text/javascript"&gt; &gt; function toggle(obj){ &gt; var el=document.getElementById('morecontent'); &gt; if (el.style.display !='none'){ &gt; el.style.display='none'; &gt; } &gt; else {el.style.display=''; &gt; } &gt; } &gt; &lt;/script&gt; &gt; &lt;p class="introcontent"&gt;Lorem ipsum dolor sit amet, consectetur &gt; adipiscing elit. Aenean in pede congue &gt; ipsum sollicitudin pellentesque. Nunc &gt; t tortor dolor, sagittis nec, placerat &gt; vel, commodo sed, nunc. Vivamus &gt; bibendum molestie orci. Duis nec leo &gt; at libero fermentum molestie. Nam eu &gt; risus.&lt;br /&gt; &gt; There's more if you press toggle... &gt; &gt; &lt;/p&gt; &gt; &lt;a href="JavaScript: toggle(this)"&gt;Toggle&lt;/a&gt; &gt; &lt;div id="morecontent" style="display:none;"&gt; &gt; &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in &gt; pede congue ipsum sollicitudin &gt; pellentesque. Nunc t tortor dolor, &gt; sagittis nec, placerat vel, commodo &gt; sed, nunc. Vivamus bibendum molestie &gt; orci. Duis nec leo at libero fermentum &gt; molestie. Nam eu risus. &gt; &lt;/p&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. &gt; Aenean in pede congue ipsum &gt; sollicitudin pellentesque. Nunc &gt; t tortor dolor, sagittis nec, placerat &gt; vel, commodo sed, nunc. Vivamus &gt; bibendum molestie orci. Duis nec leo &gt; at libero fermentum molestie. Nam eu &gt; risus. &gt; &lt;/p&gt; &gt; &lt;/div&gt; &gt; &gt; &lt;div id="fixedcontent"&gt; &gt; &lt;p&gt;This should stay 'under' the toggled content!&lt;/p&gt; &gt; &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean in &gt; pede congue ipsum sollicitudin &gt; pellentesque. Nunc t tortor dolor, &gt; sagittis nec, placerat vel, commodo &gt; sed, nunc. Vivamus bibendum molestie &gt; orci. Duis nec leo at libero fermentum &gt; molestie. Nam eu risus. &gt; &lt;/p&gt;&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. &gt; Aenean in pede congue ipsum &gt; sollicitudin pellentesque. Nunc &gt; t tortor dolor, sagittis nec, placerat &gt; vel, commodo sed, nunc. Vivamus &gt; bibendum molestie orci. Duis nec leo &gt; at libero fermentum molestie. Nam eu &gt; risus. &gt; &lt;/p&gt; &gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload