A Horizontal Accordion is achievable using CSS3, one caveat, you'd need to use a CSS Precompiler such as LESS or SASS (I use LESS here).
It requires an interesting use of an unordered list <ul>
, <label>
s and <input>
radio buttons.
@slideWidth: 3%;
@totalWidth: 100%;
.slider(@slides) {
input[type="radio"]:checked ~ .accslide {
width: @totalWidth * ((@totalWidth - (@slideWidth * @slides)) / 100);
}
}
The "class" .slider(@slides) defined above is what calculates the correct dimensions of the slide sections in relation to the screen (stated as 100% width) using the width of each slide divider (stated as 3% width).
The "class" .accslide is the actual "slide section" which is accessed as a "General Sibling".
Here's some working LESS in codepen.
To deal with the animation of the accordion each "accslide" uses another LESS "class" called .transitionArgs(@arguments), it's called a "mixin" and this allows you to handle browser cross compatibility.
.transitionArgs(@arguments) {
-webkit-transition: @arguments;
-moz-transition: @arguments;
-ms-transition: @arguments;
-o-transition: @arguments;
transition: @arguments;
}
If you have any questions, feel free to ask.