JoomlaVision > Web design > How to Create a Content Accordion in Pure CSS3 [Tutorial]

How to Create a Content Accordion in Pure CSS3 [Tutorial]

Today’s educational we will learn how to emanate a pure CSS3 ease accordion shaped on a Futurico UI Pro by Vladimir Kudinov. This will work on all browsers and desire that support a: aim selector.

How to Create a Content Accordion in Pure CSS3 [Tutorial]

Step 1 – Basic HTML Markup

Let’s create 3 divs with a conflicting id and any div will have a integrate with a difficulty of appendage and a div with a difficulty of content.

To be means to impression and open a accordion when we click on it we need to use a: aim selector. The aim selector will customarily work if we will have a integrate that points to an id and when we click on that integrate a id becomes a aim element.

div class="accordion"
	div id="tab-1"
		a href="#tab-1" class="tab"Option One/a
		div class="content"
			Content Here
		/div
	/div
	div id="tab-2"
		a href="#tab-2" class="tab"Option Two/a
		div class="content"
			Content Here
		/div
	/div
	div id="tab-3"
		a href="#tab-3" class="tab"Option Three/a
		div class="content"
			Content Here
		/div
	/div
/div

Step 2 – Accordion Basic Layout

We’ll start by adding some CSS reset styles to disturb all a margins, paddings and borders.

.accordion,.accordion div,.accordion h1,.accordion p,.accordion a,.accordion img,.accordion span,.accordion em,.accordion ul,.accordion li {
	margin: 0;
	padding: 0;
	border: none;
}

And thereafter we’ll give a firm 300px extent (290px + 5px domain left + 5px stuffing right), certification color, lifeless corners and some shadows.

.accordion {
	width: 290px;
	padding: 1px 5px 5px 5px;
	background: 

	-webkit-box-shadow: 0px 1px 0px rgba(255,255,255, .05);
	-moz-box-shadow: 0px 1px 0px rgba(255,255,255, .05);
	box-shadow: 0px 1px 0px rgba(255,255,255, .05);

	-webkit-border-radius: 2px;
	-moz-border-radius: 2px;
	border-radius: 2px;
}

Step 3 – Styling a Tab Header

Now let’s start styling a default appendage header with some CSS3 gradients, shadows, lifeless corners and some elementary CSS properties (font, padding, color, etc).

.accordion .tab {
	display: block;
	height: 35px;
	margin-top: 4px;
	padding-left: 20px;
	font: playmate 12px/35px Arial, sans-serif;
	text-decoration: none;
	color: 

	text-shadow: 1px 1px 0px rgba(0,0,0, .2);

	-webkit-border-radius: 2px;
	-moz-border-radius: 2px;
	border-radius: 2px;

	background:
	background: -moz-linear-gradient(top,  #6c6e74 0%, #4b4d51 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6c6e74), color-stop(100%,#4b4d51));
	background: -webkit-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);
	background: -o-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);
	background: -ms-linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);
	background: linear-gradient(top,  #6c6e74 0%,#4b4d51 100%);

	-webkit-box-shadow: 0px 1px 0px rgba(0,0,0, .1), inset 0px 1px 0px rgba(255,255,255, .1);
	-moz-box-shadow: 0px 1px 0px rgba(0,0,0, .1), inset 0px 1px 0px rgba(255,255,255, .1);
	box-shadow: 0px 1px 0px rgba(0,0,0, .1), inset 0px 1px 0px rgba(255,255,255, .1);
}

And thereafter we need to addition a hover and active style. We’ll change a ease and a slope tinge to a juvenile one.

.accordion .tab:hover,
.accordion div:target .tab {
	color: 

	text-shadow: 0px 1px 0px rgba(255,255,255, .15);

	background:
	background: -moz-linear-gradient(top,  #a5cd4e 0%, #6b8f1a 100%);
	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));
	background: -webkit-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);
	background: -o-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);
	background: -ms-linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);
	background: linear-gradient(top,  #a5cd4e 0%,#6b8f1a 100%);

	-webkit-box-shadow: 1px 1px 1px rgba(0,0,0, .3), inset 1px 1px 1px rgba(255,255,255, .45);
	-moz-box-shadow: 1px 1px 1px rgba(0,0,0, .3), inset 1px 1px 1px rgba(255,255,255, .45);
	box-shadow: 1px 1px 1px rgba(0,0,0, .3), inset 1px 1px 1px rgba(255,255,255, .45);
}

Step 4 – Display and Hide a Content

In this step we will bury all a ease and customarily expose it when we click on a tab. To bury we’ll use a display: none; ability and a display: block; for a aim div. We’ll also addition some transition animations to make it feeling softened and a 100px tallness for a aim div.

.accordion div .content {
	display: none;
	margin: 5px 0;
}

.accordion div:target .content {
	display: block;
}

.accordion  div {
	height: 40px;
	overflow: hidden;

	-webkit-transition: all .3s ease-in-out;
	-moz-transition: all .3s ease-in-out;
	-o-transition: all .3s ease-in-out;
	-ms-transition: all .3s ease-in-out;
	transition: all .3s ease-in-out;
}

.accordion  div:target {
	height: 100px;
}

Step 5 – The Tabs Content

HTML Markup

Let’s addition some ease to a tabs. We will create a blog post preview with a title, order text, some images and some meta info. You can change a markup as we like, this is optional, usually to make this accordion some-more complete.

div class="content"
	img src="img/post-img-1.png" alt=""
	h1The Big Elephant in a City/h1
	span5 days ago/span em class="bullet"/em span17 comments/span
	pKnown locally as "SoMa", this area was home to a dot.com crash and boasts cutting-edge restaurants and boutiques./p
	ul
		liimg src="img/thumb-1.png" alt=""/li
		liimg src="img/thumb-2.png" alt=""/li
		liimg src="img/thumb-3.png" alt=""/li
	/ul
/div

CSS Styles

The ease styles are all elementary only a CSS3 stuff, we advise we to hunt a properties that we don’t know on Google and we will find a lot of information about them.

.accordion .content h1 {
	color: white;
	font: 18px/32px Arial, sans-serif;
}

.accordion .content p {
	margin: 10px 0;
	color: white;
	font: 11px/16px Arial, sans-serif;
}

.accordion .content cove {
	font: italic 11px/12px Georgia, Arial, sans-serif;
	color:
}

.accordion .content em.bullet {
	width: 5px;
	height: 5px;
	margin: 0 5px;
	background:
	display: inline-block;

	-webkit-box-shadow: inset 1px 1px 1px rgba(255,255,255, 0.4);
	-moz-box-shadow: inset 1px 1px 1px rgba(255,255,255, 0.4);
	box-shadow: inset 1px 1px 1px rgba(255,255,255, 0.4);

	-webkit-border-radius: 5px;
	-moz-border-radius: 5px;
	border-radius: 5px;
}

.accordion .content ul li {
	list-style: none;
	float: left;
	margin: 5px 10px 5px 0;
}

.accordion .content img {
	-webkit-box-shadow: 2px 2px 6px rgba(0,0,0, .5);
	-moz-box-shadow: 2px 2px 6px rgba(0,0,0, .5);
	box-shadow: 2px 2px 6px rgba(0,0,0, .5);
}

Also change a div tallness to 360px.

.accordion  div:target {
	height: 360px;
}

Conclusion

We have finished this Pure CSS3 Content Accordion. Hope we like it and don’t forget to live some feedback or any doubt we have in a comments.

Related posts