Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I changed your code in order to do what you wanted. <a href="http://jsfiddle.net/a2v5J/28/" rel="nofollow">http://jsfiddle.net/a2v5J/28/</a></p> <p><strong>HTML</strong></p> <pre><code> &lt;button id="showmenu" type="button"&gt;Hide menu&lt;/button&gt; &lt;div id="sidemenu" class="sidemenu"&gt; &lt;!-- This is the container that resize--&gt; &lt;div id="innermenu" class="innermenu"&gt; &lt;!--This is the container to keep the width of the menucontent--&gt; &lt;!-- Here you can put whatever you want--&gt; &lt;div class="sidebarmenu"&gt; This should go left &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="table"&gt; content &lt;/div&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code> /* This is following your old structure but adds a overflow to hide the menu content when width is 0 */ .sidemenu { float:left; overflow: hidden; width: 200px; height: 500px; } /*this must have the desired width, it is going to be hidden by the overflow of the parent*/ .innermenu { height: 100%; width: 200px; background: #bcc1cb; } /*Just added the height to show it more beautiful*/ .sidebarmenu { height: 100%; } .table{ height:500px; width:300px; background:pink; float:left; left:20px; z-index: 10; } </code></pre> <p><strong>JS</strong></p> <pre><code>$(document).ready(function() { $('#showmenu').click(function() { var hidden = $('.sidebarmenu').data('hidden'); $('#showmenu').text(hidden ? 'Hide Menu' : 'Show Menu'); if(hidden){ /* One gets smaller and one gets bigger*/ $('.sidemenu').animate({ width: '200px' },500); $('.table').animate({ width: '300px' },500) } else { $('.sidemenu').animate({ width: '0px' },500); $('.table').animate({ width: '500px' },500) } $('.sidebarmenu,.image').data("hidden", !hidden); }); }); </code></pre> <p>Don't use positioning or margin but use width. I had to add two div around your menu. One is needed to keep the content of the menu with a fixed width (so it doesn't resize while you change the container dimension), and the outer div is for resizing the menu and has overflow hidden to hide the innermenu </p>
    singulars
    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.
    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