Say I have three div's which contain unique content;
- div1 = Is a Photoshop guide
- div2 = Contains a gallery of images
- div3 = Lists personal contact details
When my page loads they all need to be hidden;
- div1 = hidden
- div2 = hidden
- div3 = hidden
They are also laid ontop of one another (occupy the same space having the same width, but varying heights).
There's a horizontal menu above these divs that trigger their visbilities;
| View 1 | View 2 | View 3 |
If a user clicks 'View 1', div1 becomes visible;
- div1 = visible
- div2 = hidden
- div3 = hidden
If a user clicks 'View 2', only div2 is visible;
- div1 = hidden
- div2 = visible
- div3 = hidden
And the same for clicking 'View 3';
- div1 = hidden
- div2 = hidden
- div3 = visible
My current solution is available via JSFiddle here;
only using check-boxes and opacity settings with <div>
, <label>
and <input>
How do I go about this using only HTML and CSS (no scripts) in the smallest way possible?
- What I'm trying to achieve is a singular page design, where no external pages are used
- A background (or active) style would also be of use for the menu items (so the user knows which div they are viewing)
- The problem with the current solution is that the labels and have no selection effect and the divs do not overlap (they appear below each other like a list inside of overlapping). The logo also disappears along with item 3 when clicking a label
The trick is add a
<label>
tag after a<input type="checkbox">
and in CSS, add the selector:checked
for the input, like a trigger.HTML
CSS
See Working Fiddle
Or
See Fiddle With Explanations
07.30.2014 - UPDATE:
You said you want the divs appearing without any menu deformations, right? Try to put all
<div>
's in the bottom and put every corresponding<input>
before that. The labels stay on top.Just like that:
and in CSS:
-> See new Fiddle <-
(Sorry if my english is bad)
Try different CSS menus. You can grab a lot from google. Here are some samples collected from web: