Author: | ferry |
---|---|
Views Total: | 36,053 views |
Official Page: | Go to website |
Last Update: | March 28, 2015 |
License: | MIT |
Preview:

Description:
A responsive horizontal accordion created by ferry that makes use of CSS3 transitions and transforms to smoothly expand accordion items on mouse hover.
How to use it:
Build the Html structure for the horizontal accordion using Html lists.
<div class="accordion"> <ul> <li> <div> <a href="#"> <h2>Title 1</h2> <p>Content 1</p> </a> </div> </li> <li> <div> <a href="#"> <h2>Title 2</h2> <p>Content 2</p> </a> </div> </li> <li> <div> <a href="#"> <h2>Title 3</h2> <p>Content 3</p> </a> </div> </li> <li> <div> <a href="#"> <h2>Title 4</h2> <p>Content 4</p> </a> </div> </li> <li> <div> <a href="#"> <h2>Title 5</h2> <p>Content 5</p> </a> </div> </li> <li> <div> <a href="#"> <h2>Title 6</h2> <p>Content 6</p> </a> </div> </li> </ul> </div>
The basic CSS styles for the accordion.
.accordion { width: 100%; max-width: 1080px; height: 250px; overflow: hidden; margin: 50px auto; } .accordion ul { width: 100%; display: table; table-layout: fixed; margin: 0; padding: 0; } .accordion ul li { display: table-cell; vertical-align: bottom; position: relative; width: 16.666%; height: 250px; background-repeat: no-repeat; background-position: center center; transition: all 500ms ease; } .accordion ul li div { display: block; overflow: hidden; width: 100%; } .accordion ul li div a { display: block; height: 250px; width: 100%; position: relative; z-index: 3; vertical-align: bottom; padding: 15px 20px; box-sizing: border-box; color: #fff; text-decoration: none; font-family: Open Sans, sans-serif; transition: all 200ms ease; } .accordion ul li div a * { opacity: 0; margin: 0; width: 100%; text-overflow: ellipsis; position: relative; z-index: 5; white-space: nowrap; overflow: hidden; -webkit-transform: translateX(-20px); transform: translateX(-20px); -webkit-transition: all 400ms ease; transition: all 400ms ease; } .accordion ul li div a h2 { font-family: Montserrat, sans-serif; text-overflow: clip; font-size: 24px; text-transform: uppercase; margin-bottom: 2px; top: 160px; } .accordion ul li div a p { top: 160px; font-size: 13.5px; }
Add background images to the accordion items.
.accordion ul li:nth-child(1) { background-image: url("1.jpg"); } .accordion ul li:nth-child(2) { background-image: url("2.jpg"); } .accordion ul li:nth-child(3) { background-image: url("3.jpg"); } .accordion ul li:nth-child(4) { background-image: url("4.jpg"); } .accordion ul li:nth-child(5) { background-image: url("5.jpg"); } .accordion ul li:nth-child(6) { background-image: url("6.jpg"); }
Expand the accordion item on mouse hover using :hover pseudo element.
.accordion ul:hover li { width: 8%; } .accordion ul:hover li:hover { width: 60%; } .accordion ul:hover li:hover a { background: rgba(0, 0, 0, 0.4); } .accordion ul:hover li:hover a * { opacity: 1; -webkit-transform: translateX(0); transform: translateX(0); }
Make the accordion responsive using CSS media queries.
@media screen and (max-width: 600px) { .accordion { height: auto; } .accordion ul li, .accordion ul li:hover, .accordion ul:hover li, .accordion ul:hover li:hover { position: relative; display: table; table-layout: fixed; width: 100%; -webkit-transition: none; transition: none; } }
Nice work!! It was a great help! Just one question… Is it possible to add auto transition between the pages? Thank you!
Great example – was able to take this and incorporate into WordPress static page – thanks!
Nice!
I need to add a title -text- when the item is close.
May you help me on how to do it?
Thanks,
Marcos
I want to do this with an image tag in the html code instead of a background image in the css. Is it possible?
Hi There! Is it possible to push all all items to right only showing say 10% of each list item and on hover, have them slide to the left and open up completely or to a percentage I chose?
thank you