JSFiddle - React, Tailwind, and code Playground
HTML
<h1>CSS + HTML only Accordion Element
<div>
<a href="#" onClick="window.print();">
<img alt="Print" src="http://support.microsoft.com/library/images/support/CN/print-icon-white.png" />
<span>Print</span>
</a>
<a href="mailto:[email protected]">
<img alt="Email" src="http://support.microsoft.com/library/images/support/CN/email-icon.png" />
<span>Email</span>
</a>
</div>
</h1>
<ul>
<span id="expand">Expand all</span><span> | </span><span id="collapse">Collapse all</span>
<li>
<input type="checkbox" id="box1" checked />
<label for="box1"><div></div>LANGUAGES USED</label>
<p>This page was written in HTML and CSS. The CSS was compiled from SASS. I used Normalize as my CSS reset and -prefix-free to save myself some headaches. I haven't quite gotten the hang of Slim for compiling into HTML, but someday I'll use it since its syntax compliments that of SASS. Regardless, this could all be done in plain HTML and CSS.</p>
</li>
<li>
<input type="checkbox" id="box2"/>
<label for="box2"><div></div>HOW IT WORKS</label>
<p>Using the sibling and checked selectors, we can determine the styling of sibling elements based on the checked state of the checkbox input element. One use, as demonstrated here, is an entirely CSS and HTML accordion element. Media queries are used to make the element responsive to different screen sizes.</p></li>
<li>
<input type="checkbox" id="box3" />
<label for="box3"><div></div>POINTS OF INTEREST</label>
<p>By making the open state default for when :checked isn't detected, we can make this system accessable for browsers that don't recognize :checked. The fallback is simply an open accordion. The accordion can be manipulated with Javascript (if needed) by changing the "checked" property of the input element.</p></li>
</ul>
CSS
h1 a {
color:#fff;
display:block;
font-family:"Segoe UI", "Segoe UI Semibold", "Segoe UI Bold";
font-size:12px;
line-height:16px;
margin-top:10px;
text-decoration:none
}
a > img {
vertical-align:middle
}
ul span {
font-family:Segoe UI, Arial, Verdana, Tahoma, sans-serif;
line-height:50px;
font-size:13px;
color:#0066cc
}
#expand:hover, #collapse:hover {
cursor:pointer;
text-decoration:underline
}
h1 > div {
position:absolute;
top:40px;
right:30px;
float:right
}
h1 {
background:#1076c1;
color:#fff;
font-family:"Segoe UI light", "Segoe UI", Arial, Tahoma, sans-serif;
font-size:40px;
font-weight:normal;
line-height:44px;
padding:40px 80px 40px 40px
}
input {
display:none
}
label:hover {
text-decoration:underline
}
input[type=checkbox]:checked ~ label > div {
background-image:
url("http://support.microsoft.com/library/images/support/en-us/20x20_grey_minus.png");
background-repeat:no-repeat
}
input[type=checkbox]:checked ~ p {
padding:20px;
height:auto
}
label {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor:pointer;
padding:10px;
background-color:#d1d3d4;
font-family:Segoe UI, Arial, Verdana, Tahoma, sans-serif;
font-size:16px;
font-weight:lighter;
display:block
}
label > div {
height:20px;
width:20px;
background-image:
url("http://support.microsoft.com/library/images/support/en-us/20x20_grey_plus.png");
background-repeat:no-repeat;
margin:0px 10px -5px 0px;
display:inline-block
}
li > p {
margin-top:-8px;
overflow:hidden;
height:0px;
font-family:"Segoe UI regular", "Segoe UI", Arial, Tahoma, sans-serif;
font-size:13px
}
ul {
list-style:none;
padding:0
}
JavaScript
$("#expand").click( function() {
$(":checkbox").prop("checked", true);
});
$("#collapse").click( function() {
$(":checkbox").prop("checked", false);
});