I’m using a “windowed layout” (that is, the content inside certain divs look like in-browser windows, for a web-app look), and I’d like for the following function:
- When a div is clicked, it gets smaller so as to not take up space. When it is clicked again it re-expands.
This is an example for a simple page with two <div>s:
Suppose <div id="window1"> and <div id="window2">
#window1 {
width: 30px;
}
#window1:active {
width: 100px;
}
Problem is, once the mouse button is let go of, the width returns to its original size.
Basically the page has a little menu at the bottom left of the screen (fixed) that I would like to get out of the way for people with smaller resolutions (1024 and under) because it will get in the way of the text.
Here’s how I’d do it using :target – http://jsfiddle.net/joplomacedo/V6pJT/3/
Html
CSS
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:
The HTML…
…and the CSS…