Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's how I'd do it using :target - <a href="http://jsfiddle.net/joplomacedo/V6pJT/3/" rel="nofollow">http://jsfiddle.net/joplomacedo/V6pJT/3/</a></p> <p>Html</p> <pre><code>&lt;div class="block"&gt; &lt;a class="open" href="#menu"&gt;&lt;/a&gt; &lt;div id="menu"&gt; Menu Item 1&lt;br /&gt; Menu Item 2&lt;br /&gt; Menu Item 3&lt;br /&gt; Menu Item 4&lt;br /&gt; Menu Item 5&lt;br /&gt; Menu Item 6&lt;br /&gt; Menu Item 7&lt;br /&gt; &lt;a class="close" href="#"&gt;&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>.block { position: relative; } #menu{ width: 100px; background: red; border: 1px solid #aaa; } #menu:target { background: orange; width: 200px; } .open, .close { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .close { display: none; } #menu:target .close { display: block; } </code></pre> <p>​Unfortunately this solution makes the page jump every time you click it. It's unnecessarily big too. A solution taking advantage of the :checked selector would require much less html and css and it also wouldn't have the page jump on every click. Here's that solution, and the one I recommend:</p> <p>The HTML...</p> <pre><code>&lt;div class="block"&gt; &lt;label for="toggle"&gt;&lt;/label&gt; &lt;input type="checkbox" id="toggle"/&gt; &lt;div id="menu"&gt; Menu Item 1&lt;br /&gt; Menu Item 2&lt;br /&gt; Menu Item 3&lt;br /&gt; Menu Item 4&lt;br /&gt; Menu Item 5&lt;br /&gt; Menu Item 6&lt;br /&gt; Menu Item 7&lt;br /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>...and the CSS...</p> <pre><code>.block { position: fixed; bottom: 0; } #toggle { display: none; } label[for="toggle"] { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } #menu{ width: 100px; background: red; border: 1px solid #aaa; } #toggle:checked ~ #menu { background: orange; width: 200px; } </code></pre> <p>​</p> <p>​</p>
 

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