Skip to content

Instantly share code, notes, and snippets.

@nurtext
Created October 22, 2013 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurtext/7103252 to your computer and use it in GitHub Desktop.
Save nurtext/7103252 to your computer and use it in GitHub Desktop.
Simple CSS3 based horizontal accordion
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>CSS3 Accordion</title>
<style>
#accordion {
width: 810px;
height: 600px;
margin: 20px auto;
overflow: hidden;
cursor: pointer;
}
#accordion:after {
content: " ";
float: none;
clear: both;
}
.cell {
width: 25%;
height: 600px;
float: left;
-webkit-transition: width .5s ease-in-out;
-moz-transition: width .5s ease-in-out;
-ms-transition: width .5s ease-in-out;
transition: width .5s ease-in-out;
}
.cell:nth-child(1)
{
background: url(http://placehold.it/600x600/cccccc/ffffff&text=%20%20Cell%201%20%20) top center no-repeat;
}
.cell:nth-child(2)
{
background: url(http://placehold.it/600x600/ff0000/ffffff&text=%20%20Cell%202%20%20) top center no-repeat;
}
.cell:nth-child(3)
{
background: url(http://placehold.it/600x600/00ff00/ffffff&text=%20%20Cell%203%20%20) top center no-repeat;
}
.cell:nth-child(4)
{
background: url(http://placehold.it/600x600/0000ff/ffffff&text=%20%20Cell%204%20%20) top center no-repeat;
}
.cell.active {
width: 50%;
}
.cell.inactive {
width: 16.666%;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function()
{
$('.cell').mouseenter(function()
{
$(this).addClass('active');
$('#accordion').children().not($(this)).addClass('inactive');
})
.mouseleave(function()
{
$(this).removeClass('active');
$('#accordion').children().not($(this)).removeClass('inactive');
});
});
</script>
</head>
<body>
<div id="accordion">
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
</div>
</body>
</html>
@nurtext
Copy link
Author

nurtext commented Nov 13, 2013

A rip-off of my work can be found here:
http://codepen.io/Beormalte/details/eoGDy

Too sad he didn't gave credit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment