Skip to content

Instantly share code, notes, and snippets.

@natejacobson
Created July 7, 2015 23: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 natejacobson/a8b9aaa849b370b54326 to your computer and use it in GitHub Desktop.
Save natejacobson/a8b9aaa849b370b54326 to your computer and use it in GitHub Desktop.
Simple Datalist Accordion
<script>$('.folded dt').click( function() { $(this).toggleClass('unfolded').next('dd').toggleClass('unfolded'); });</script>
<style>
.folded dt,
.folded dd {
display: block;
}
.folded dt {
font-size: 1.2rem;
padding: .5rem 0;
font-weight: 300;
}
.folded dt:nth-of-type(odd)
.folded dt:nth-of-type(odd) + dd {
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,ffffff+50,ffffff+100&amp;0+0,1+50,0+100 */
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 50%, rgba(255,255,255,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(50%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 50%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 50%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 50%,rgba(255,255,255,0) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(255,255,255,1) 50%,rgba(255,255,255,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
.folded dt:not(.unfolded):nth-of-type(even),
.folded dt:not(.unfolded):nth-of-type(even) + dd {
/* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#ffffff+0,eaeaea+50,ffffff+100&amp;0+0,1+50,0+100 */
background: -moz-linear-gradient(left, rgba(255,255,255,0) 0%, rgba(234,234,234,1) 50%, rgba(255,255,255,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(50%,rgba(234,234,234,1)), color-stop(100%,rgba(255,255,255,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(234,234,234,1) 50%,rgba(255,255,255,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(234,234,234,1) 50%,rgba(255,255,255,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(255,255,255,0) 0%,rgba(234,234,234,1) 50%,rgba(255,255,255,0) 100%); /* IE10+ */
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(234,234,234,1) 50%,rgba(255,255,255,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#00ffffff',GradientType=1 ); /* IE6-9 */
}
.folded dt {
border-top: 1px transparent solid;
}
.folded dd {
display: none;
}
.folded dt.unfolded,
.folded dd.unfolded {
color: black;
}
.folded dt.unfolded {
border-top: 1px $gray solid;
padding-top: 1rem;
padding-bottom: .25rem;
}
.folded dt.unfolded + dd {
border-bottom: 1px rgba(0, 0, 0, 0.1) solid;
}
.folded dd {
opacity: .5;
transition: opacity .5s ease-in;
}
.folded dd.unfolded {
display: block;
padding-bottom: 1rem;
opacity: 1;
}
.folded dt:hover {
cursor: pointer;
color: black;
}
</style>
<dl>
<dt>List Item Title and Toggle</dt>
<dd>Content hidden until toggled</ddi>
</dl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment