<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codrops &#187; CSS3</title>
	<atom:link href="http://tympanus.net/codrops/tag/css3/feed/" rel="self" type="application/rss+xml" />
	<link>http://tympanus.net/codrops</link>
	<description>Useful resources and inspiration for creative minds</description>
	<lastBuildDate>Mon, 17 Jun 2013 21:34:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Creative Button Styles</title>
		<link>http://tympanus.net/codrops/2013/06/13/creative-button-styles/</link>
		<comments>http://tympanus.net/codrops/2013/06/13/creative-button-styles/#comments</comments>
		<pubDate>Thu, 13 Jun 2013 10:29:40 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[hover]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15430</guid>
		<description><![CDATA[Some creative and modern button styles and effects for your inspiration. ]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/CreativeButtons/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/06/CreativeButtons.png" alt="Creative Button Styles" width="580" height="315" class="alignnone size-full wp-image-15436" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/CreativeButtons/">View demo</a> <a class="download" href="http://tympanus.net/Development/CreativeButtons/CreativeButtons.zip">Download source</a></p>
<p>Today we would like to give you some button inspiration. This button set consists of some simple, creative and subtle styles and effects to inspire you. The effects can be seen when hovering on some buttons and clicking on others. Mostly, CSS transitions are used but also CSS animations and for some buttons we use a bit of JavaScript to add/remove effect classes.  </p>
<p>The icons, which we add using the :before (and sometimes :after) pseudo-class, are from IcoMoon and we&#8217;ve created them with the <a href="http://icomoon.io/app/">IcoMoon app</a>.</p>
<div class="ct-special-box"><strong>Please note: this only works as intended in browsers that support the respective CSS properties.</strong></div>
<p>The markup of a button is really simple. We just add specific shared classes:</p>
<pre class="brush:html">
&lt;button class="btn btn-6 btn-6d"&gt;Button&lt;/button&gt;
</pre>
<p>The common styles for all the buttons are some resets defined in .btn and we use the specific numbered classes for the different sets of styles. That numbered class are the shared styles for the sets. Each button has an additional specific class then. When using an icon, we add the icon-class which will use the pseudo element :before to add the character from the icon font.</p>
<p>An example for a specific button style is the following:</p>
<pre class="brush:css">
/* Button 6d */
.btn-6d {
	border: 2px dashed #226fbe;
}

.btn-6d:hover {
	background: transparent;
	color: #226fbe;
}
</pre>
<p>Which will of course depend on what we define as a common style in .btn and .btn-6. </p>
<p><em>This class structure is used for demo purposes. Using a single style, the properties should of course be merged into a single class.</em></p>
<p>I hope you enjoy the styles and find them inspiring! </p>
<div class="ct-github-link"><a href="https://github.com/codrops/CreativeButtons">Find this project on Github and contribute</a></div>
<p><a class="demo" href="http://tympanus.net/Development/CreativeButtons/">View demo</a> <a class="download" href="http://tympanus.net/Development/CreativeButtons/CreativeButtons.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/06/13/creative-button-styles/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Simple Icon Hover Effects</title>
		<link>http://tympanus.net/codrops/2013/05/30/simple-icon-hover-effects/</link>
		<comments>http://tympanus.net/codrops/2013/05/30/simple-icon-hover-effects/#comments</comments>
		<pubDate>Thu, 30 May 2013 13:16:13 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[hover]]></category>
		<category><![CDATA[icon]]></category>
		<category><![CDATA[pseudo-element]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15265</guid>
		<description><![CDATA[A set of simple round icon hover effects with CSS transitions and animations for your inspiration.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/IconHoverEffects/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/IconHoverEffects1.png" alt="IconHoverEffects" width="580" height="315" class="alignnone size-full wp-image-15271" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/IconHoverEffects/">View demo</a> <a class="download" href="http://tympanus.net/Development/IconHoverEffects/IconHoverEffects.zip">Download source</a></p>
<p>Today we want to share some simple icon hover effects with you. The idea is to create a subtle and stylish effect using CSS transitions and animations on the anchors and their pseudo-elements. For the icons we are using an icon font (<a href="http://dribbble.com/shots/665585-Eco-Ico">Eco Ico by Matthew Skiles</a>, created with the <a href="http://icomoon.io/app/">IcoMoon app</a>) which we add using the :before pseudo-class.</p>
<div class="ct-special-box"><strong>Please note: this only works as intended in browsers that support the respective CSS properties.</strong></div>
<p>The markup only uses an anchor for the icon and we wrap a set into a container so that we can create a variety of effects:</p>
<pre class="brush:html">
&lt;div class="hi-icon-wrap hi-icon-effect-1 hi-icon-effect-1a"&gt;
	&lt;a href="#" class="hi-icon hi-icon-mobile"&gt;Mobile&lt;/a&gt;
	&lt;a href="#" class="hi-icon hi-icon-screen"&gt;Desktop&lt;/a&gt;
	&lt;a href="#" class="hi-icon hi-icon-earth"&gt;Partners&lt;/a&gt;
	&lt;a href="#" class="hi-icon hi-icon-support"&gt;Support&lt;/a&gt;
	&lt;a href="#" class="hi-icon hi-icon-locked"&gt;Security&lt;/a&gt;
&lt;/div&gt;
</pre>
<p>An example for a hover effect is the simple rotation of the pseudo-element for the icon:</p>
<pre class="brush:css">
.hi-icon-effect-6 .hi-icon {
	box-shadow: 0 0 0 4px rgba(255,255,255,1);
	transition: background 0.2s, color 0.2s;	
}

.no-touch .hi-icon-effect-6 .hi-icon:hover {
	background: rgba(255,255,255,1);
	color: #64bb5d;
}

.no-touch .hi-icon-effect-6 .hi-icon:hover:before {
	animation: spinAround 2s linear infinite;
}

@keyframes spinAround {
	from {
		transform: rotate(0deg)
	}
	to {
		transform: rotate(360deg);
	}
}
</pre>
<p><em>Note that a dashed border on a round pseudo-element (border-radius: 50%) does not work in FF 21.0 (effect 4)</em></p>
<p>I hope you enjoy the effects and find them inspiring! </p>
<div class="ct-github-link"><a href="https://github.com/codrops/IconHoverEffects">Find this project on Github</a></div>
<p><a class="demo" href="http://tympanus.net/Development/IconHoverEffects/">View demo</a> <a class="download" href="http://tympanus.net/Development/IconHoverEffects/IconHoverEffects.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/30/simple-icon-hover-effects/feed/</wfw:commentRss>
		<slash:comments>64</slash:comments>
		</item>
		<item>
		<title>Examples of Pseudo-Elements Animations and Transitions</title>
		<link>http://tympanus.net/codrops/2013/05/22/examples-of-pseudo-elements-animations-and-transitions/</link>
		<comments>http://tympanus.net/codrops/2013/05/22/examples-of-pseudo-elements-animations-and-transitions/#comments</comments>
		<pubDate>Wed, 22 May 2013 11:25:40 +0000</pubDate>
		<dc:creator>Marco Barria</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[pseudo-class]]></category>
		<category><![CDATA[pseudo-element]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15166</guid>
		<description><![CDATA[Some creative experiments that use animations and transitions on pseudo-elements to create interesting effects.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/AnimatingTransitioningPseudoElements.jpg" alt="AnimatingTransitioningPseudoElements" width="580" height="315" class="alignnone size-full wp-image-15181" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/">View demo</a> <a class="download" href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/PseudoElementsAnimationsTransitions.zip">Download source</a></p>
<p>Today we are going to experiment with animations and transitions on pseudo-elements (:before and :after) and we are going to discover their potential. We will talk a bit about animating pseudo-elements and look at four examples that use some special techniques to achieve a variety of effects.</p>
<p>Let&#8217;s first have a look at the advantages and disadvantages that come along with using animations and transitions together with pseudo-elements.</p>
<h3>Advantages</h3>
<ul>
<li>Simplification and optimization of HTML markup</li>
<li>Taking advantage of CSS3 capacities</li>
<li>Contributing to design</li>
</ul>
<h3>Disadvantages</h3>
<ul>
<li>Only supported by modern browsers like Firefox, IE10 and recently Chrome (see <a href="http://css-tricks.com/transitions-and-animations-on-css-generated-content/" target="_blank">this updated support table</a> for more info)</li>
<li>Does not work in mobile browsers yet</li>
<li>Pseudo-elements cannot be identified by ID</li>
<li>Pseudo-elements don&#8217;t appear in the DOM.</li>
<li><a href="http://stackoverflow.com/questions/5041494/manipulating-css-pseudo-elements-using-jquery-e-g-before-and-after">Pseudo-elements can&#8217;t be animated with JavaScript</a></li>
</ul>
<p>It is clear that there are more disadvantages than advantages, but I think that we should be excited about the future and give it a try!</p>
<p>The following four examples were created for this specific topic. It is clear that there are other ways for reaching the same visual effects, but for the sake of this experiment, we&#8217;ll of course use pseudo-elements so <strong>be aware that it only works in browsers that support their animations and transitions</strong>.</p>
<p>Please note:</p>
<ul>
<li>In this tutorial we will omit vendor prefixes, but you will find them in the download files.</li>
<li>For both examples we will primarily use the box-shadow property and EM units. </li>
</ul>
<p>A very interesting fact: pseudo-elements inherit the properties from their parent. In the case of the animations all the transformations affect them directly. This can come in handy if we want to maximize the support. Check out <a href="http://kizu.ru/en/pseudos/">Use CSS transitions for pseudo-elements right now</a> by Roman Komarov for more on that matter.</p>
<p><strong>Let&#8217;s start!</strong></p>
<h3>Example 1</h3>
<p><a href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/index.html"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/AnimatingTransitioningPseudoElements01.png" alt="AnimatingTransitioningPseudoElements01" width="814" height="500" class="alignnone size-full wp-image-15175" /></a></p>
<p>First, we&#8217;re going to do a fun thing: an animation of a drop of water falling into a rounded container (based on the Codrops logo)</p>
<h4>The Markup</h4>
<pre class="brush:html">
&lt;div class="drop"&gt;&lt;/div&gt;
</pre>
<p>We only have one element, although it could have another container that helps the change of scale.</p>
<h4>The CSS</h4>
<pre class="brush:css">
*,
*:before,
*:after {
    box-sizing: border-box;
}

.drop {
	background: rgba(255, 255, 245, 1);
	border: 4px solid rgba(255, 245, 235, 1);
	border-radius: 100%;
	box-shadow: inset -0.1em 0 2em 0.5em rgba(255, 255, 255, 0.5), 
	            inset -0.1em 0 0.5em 0 rgba(0, 0, 0, 0.8);
	position: relative;
	margin: 0 auto;
	width: 15em; 
	height: 15em;
	overflow: hidden;
}

.drop:before,
.drop:after {
	content:"";
	display:block;
	position:absolute;
}

/* Drop */

.drop:before {
	background: rgba(167, 217, 234, 1);
	border-radius: 100%;
	
	/* Drop start */
	
	box-shadow: 0 0 0 0.1em rgba(167, 217, 234, 0.8), 
	            0 0 0 0.15em rgba(167, 217, 234, 0.8), 
	            0 0 0 0.2em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.25em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.3em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.35em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.4em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.45em rgba(167, 227, 234, 0.8), 
	            0 0 0 0.5em rgba(167, 227, 234, 0.8);
	top: 0%; left: 50%;
	
	/* The "width" and "height" of the division must be smaller than the "box-shadow" total size. So we can control different variant sizes. */
	
	width: 0.2em; 
	height: 0.2em;
	animation: fall 3.5s cubic-bezier(0.5, 0, 1, 0.5) infinite;
}

/* Surface */

.drop:after {
	background: rgb(52, 152, 219);
	background: linear-gradient(rgba(52, 255, 255, 1) 0%, rgba(52, 152, 219, 1) 10%, rgba(152, 252, 219, 1) 100%);
	border-radius: 100% 0 50% 0;
	left: 0; 
	bottom: 0;
	width: inherit; 
	height: 3em;
	opacity: 0.7;
	animation: surface 3s linear infinite;
}

/* Drop animation */

@keyframes fall  {

	/* Drop form */

	5%, 15%  {
		box-shadow: 0 -1.4em 0 0.1em rgba(167, 217, 234, 1), 
		            0 -0.8em 0 0.15em rgba(167, 217, 234, 1), 
		            0 -0.3em 0 0.2em rgba(167, 217, 234, 1), 
		            0 -0.1em 0 0.25em rgba(167, 217, 234, 1), 
		            0 0 0 0.3em rgba(167, 217, 234, 1), 
		            0 0.2em 0 0.35em rgba(167, 217, 234, 1), 
		            0 0.4em 0 0.4em rgba(167, 217, 234, 1), 
		            0 0.6em 0 0.45em rgba(167, 217, 234, 1), 
		            0 0.8em 0 0.5em rgba(167, 217, 234, 1);
	}
	
	/* Drop fall */
	
	16%  {
		top: 80%;
	}
	
	/* Contact surface */
	
	18%  {
		top: 80%;
		box-shadow: 1em -8em 0 0.2em rgba(177, 227, 234, 1), 
		            -2.2em -3.8em 0 0.1em rgba(177, 227, 234, 1), 
		            3em -2.85em 0 0.3em rgba(177, 227, 234, 1), 
		            -3.5em -4em 0 0.2em rgba(177, 227, 234, 1), 
		            0 0 0 0.3em rgba(177, 227, 234, 1), 
		            2em -2em 0 0.2em rgba(177, 227, 234, 1), 
		            -0.3em -3em 0 0.2em rgba(177, 227, 234, 1), 
		            0.5em -5em 0 0.35em rgba(177, 227, 234, 1), 
		            -3em -1em 0 0.3em rgba(177, 227, 234, 1);
	}
	
	/* Dispersion */
	
	30%  {
		top: 90%;
		box-shadow: 1.5em 0 0 0.2em rgba(252, 252, 255, 0.1), 
		            -2em 0 0 0.15em rgba(252, 252, 255, 0.1), 
		            3em 0 0 0.2em rgba(252, 252, 255, 0.1), 
		            -2em 0 0 0.25em rgba(252, 252, 255, 0.1), 
		            0 0 0 0.2em rgba(252, 252, 255, 0.1), 
		            2.35em 0 0 0.3em rgba(252, 252, 255, 0.1), 
		            -0.5em 0 0 0.2em rgba(252, 252, 255, 0.1), 
		            1em 0 0 0.3em rgba(252, 252, 255, 0.1), 
		            -4em 0 0 0.4em rgba(252, 252, 255, 0.1);
	}
	
	/* Hidden */
	
	40%, 100%  {
		top: 95%;
		background: rgba(255, 255, 255, 1);
		box-shadow: 1.8em 0.5em 0 0.2em rgba(255, 255, 255, 0), 
		            -3em 0.5em 0 0.1em rgba(255, 255, 255, 0), 
		            4em 0.5em 0 0.1em rgba(255, 255, 255, 0), 
		            -3.5em 0.5em 0 0.1em rgba(255, 255, 255, 0), 
		            0 0 0 0.3em rgba(255, 255, 215, 0), 
		            2.45em 0.5em 0 0.1em rgba(255, 255, 255, 0), 
		            -0.8em 0.5em 0 0.2em rgba(255, 255, 255, 0), 
		            1.5em 0.5em 0 0.3em rgba(255, 255, 255, 0), 
		            -4.5em 0.5em 0 0.2em rgba(255, 255, 255, 0);
	}
}

/* Animation of water surface */

@keyframes surface  {
	50%  {
		border-radius: 0 75% 0 75%;
		opacity: 0.5;
		height: 3.5em;
	}
}
</pre>
<p>Here are two tips for obtaining more naturalistic animations:</p>
<ul>
<li>Watch and analyze references like images, videos, etc.</li>
<li>Experiment with different speeds for transitioning CSS properties and for keyframes.</li>
</ul>
<p>More about animating characters, but definitely fun and worth exploring is the <a href="http://www.theanimatorssurvivalkit.com/">&#8220;The Animator&#8217;s Survival Kit&#8221; by Richard Williams</a>. </p>
<p>Let&#8217;s go back to our subject. In this last example the :before pseudo-class has the same width like the father. In order not to have unexpected problems of overflowing we will use the &#8220;inherit&#8221; value.</p>
<h3>Example 2</h3>
<p><a href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/index2.html"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/AnimatingTransitioningPseudoElements02.png" alt="AnimatingTransitioningPseudoElements02" width="814" height="500" class="alignnone size-full wp-image-15176" /></a></p>
<p>In this example we will create a hover effect by using a transition.</p>
<h4>The Markup</h4>
<pre class="brush:html">

&lt;div class="circle"&gt;
	&lt;h1&gt;codrops&lt;/h1&gt;
&lt;/div&gt;

</pre>
<p>Here we just have a container and a heading to separate the text from the rest.</p>
<h4>The CSS</h4>
<pre class="brush:css">
.circle {
	background: rgb(255,255,255);
	border-radius: 100%;
	cursor: pointer;
	position: relative;
	margin: 0 auto;
	width: 15em; 
	height: 15em;
	overflow: hidden;
	transform: translateZ(0);
}

.circle h1 {
	color: rgba(189, 185, 199,0);
	font-family: 'Lato', sans-serif;
	font-weight: 900;
	font-size: 1.6em;
	line-height: 8.2em;
	text-align: center;
	text-transform: uppercase;
	-webkit-font-smoothing: antialiased;
	user-select: none;
	transition: color 0.8s ease-in-out;
}

.circle:before,
.circle:after {
	border-radius: 100%;
	content:"";
	position: absolute;
	top: 0; 
	left: 0;
	width: inherit; 
	height: inherit;			
	box-shadow: inset 10.6em 0 0 rgba(30, 140, 209, 0.2), 
	            inset 0 10.6em 0 rgba(30, 140, 209, 0.2), 
	            inset -10.6em 0 0 rgba(30, 140, 209, 0.2), 
	            inset 0 -10.6em 0 rgba(30, 140, 209, 0.2);
	transition: box-shadow 0.75s;
}

/* We rotate the :after pseudo-element to get the edge from the corner, we could also just do that with box-shadows. */

.circle:after  {
	transform: rotate(45deg);
}

/* There is no problem using "pseudo-class + pseudo-element" :) */

.circle:hover:before,
.circle:hover:after  {
	box-shadow: inset 0.86em 0 0 rgba(255, 0, 0, 0.5), 
	            inset 0 0.86em 0 rgba(252, 150, 0, 0.5), 
	            inset -0.86em 0 0 rgba(0, 255, 0, 0.5),	
	            inset 0 -0.86em 0 rgba(0, 150, 255, 0.5);
}

.circle:hover > h1  {
	color: rgba(185, 185, 185,1);
}
</pre>
<p>You have to use only one color at a time, to avoid an unwanted mixing of colors by overlapping when triggering the hover.</p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<h3>Example 3</h3>
<p><a href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/index3.html"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/AnimatingTransitioningPseudoElements03.png" alt="AnimatingTransitioningPseudoElements03" width="814" height="500" class="alignnone size-full wp-image-15177" /></a></p>
<p>How could we dare to leave out the indispensable spinner loading animation!<br />
The idea here is to merge colors through the rotation. It&#8217;s very simple!</p>
<h4>The Markup</h4>
<pre class="brush:html">
&lt;div class="loading"&gt;&lt;/div&gt;
</pre>
<p>We&#8217;ll just use one single element for the markup.</p>
<h4>The CSS</h4>
<pre class="brush:css">
.loading  {
	background: rgba(0, 50, 250, 0);
	position: relative;
	margin: 5em auto 0 auto;
	width: 3em; 
	height: 3em;
	animation-name:rotate;
}

.loading,
.loading:before,
.loading:after  {
	border-radius: 100%;
	animation-duration: 3s;
	animation-iteration-count: infinite;
	animation-timing-function: ease-in;
}

.loading:before,
.loading:after  {
	content: "";
	position: absolute;
	top: 0; 
	left: 0;
	width: inherit; 
	height: inherit;
}

.loading:before  {
	background: rgba(200, 250, 100, 0);
	animation-name: ring;
}

.loading:after  {
	background: rgba(250, 0, 200, 0);
	animation-name: ring2;
}

@keyframes rotate  {
	0%  {
		transform: rotateZ(0deg) scaleX(0.1) scaleY(0.1) translateZ(0);
		box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5), 
					inset 0 0.8em 0 rgba(252, 150, 0, 0.5), 
					inset -0.8em 0 0 rgba(0, 255, 0, 0.5), 
					inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
	}
	
	/* hidden */
	
	85%, 100%  {
	
	/* 360deg * 10 */
	
		transform: rotateZ(3600deg) scaleX(2.01) scaleY(2) translateZ(0);
		box-shadow: inset 0 0 0 rgba(255, 0, 0, 0), 
					inset 0 0 0 rgba(252, 150, 0, 0), 
					inset 0 0 0 rgba(0, 255, 0, 0), 
					inset 0 0 0 rgba(0, 150, 255, 0);
	}
}

@keyframes ring  {
	0%  {
		transform: scaleX(0.1) scaleY(0.5);
		box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5), 
					inset 0 0.8em 0 rgba(252, 150, 0, 0.5), 
					inset -0.8em 0 0 rgba(0, 255, 0, 0.5), 
					inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
	}
	
	/* hidden */
	
	75%, 100%  {
		transform: scaleX(2) scaleY(2.1);
		box-shadow: inset 0 0 0 rgba(255, 0, 0, 0), 
					inset 0 0 0 rgba(252, 150, 0, 0), 
					inset 0 0 0 rgba(0, 255, 0, 0), 
					inset 0 0 0 rgba(0, 150, 255, 0);
	}
}

@keyframes ring2  {
	0%  {
		transform: scaleX(0.5) scaleY(0.1);
		box-shadow: inset 0.8em 0 0 rgba(255, 0, 0, 0.5), 
					inset 0 0.8em 0 rgba(252, 150, 0, 0.5), 
					inset -0.8em 0 0 rgba(0, 255, 0, 0.5), 
					inset 0 -0.8em 0 rgba(0, 150, 255, 0.5);
	}
	
	/* hidden */
	
	65%, 100%  {
		transform: scaleX(2) scaleY(2.1);
		box-shadow: inset 0 0 0 rgba(255, 0, 0, 0), 
					inset 0 0 0 rgba(252, 150, 0, 0), 
					inset 0 0 0 rgba(0, 255, 0, 0), 
					inset 0 0 0 rgba(0, 150, 255, 0);
	}
}
</pre>
<p>This is a great example of experimenting with timings and speeds to get a really smooth animation.</p>
<h3>Example 4</h3>
<p><a href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/index4.html"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/AnimatingTransitioningPseudoElements04.png" alt="AnimatingTransitioningPseudoElements04" width="814" height="500" class="alignnone size-full wp-image-15178" /></a></p>
<p>This is the most crazy and extravagant example from all: a little one-eyed flying creature!<br />
We are going to use both, animations and transitions. </p>
<h4>The Markup</h4>
<pre class="brush:html">

&lt;div class="pojoro"&gt;&#9679;&lt;/div&gt;

</pre>
<p>We will use one element for the creature&#8217;s eye.</p>
<h4>The CSS</h4>
<pre class="brush:css">
.pojoro  {
	background: rgba( 255, 255, 255, 1);
	background: radial-gradient(ellipse at center, rgba(255,255,255,1) 40%,rgba(51,51,51,1) 100%);
	border-radius: 100%;
	
	/* box-shadow: secondary color, body, eyelash */
	
	box-shadow: 0 0 0 0.2em rgb(146,89,149), 
				0 0 0.1em 0.55em rgb(176,89,179), 
				inset 0 0.2em 0 0 rgb(136,79,139);
	
	/* ojo (eye) */
	
	color: rgba( 40, 40, 40, 0.8);
	line-height: 1.1em;
	padding-left: 0.18em;
	-webkit-font-smoothing: antialiased;
	user-select: none;
	
	/* usability, position and transition */
	
	cursor: pointer;
	position: relative;
	margin: 5em auto 0 auto;
	width: 1em; height: 1em;
	transform-origin: center;
	transition: all 0.8s ease-in-out;
	
	/* Separate the animations to have a better control over the eye and the body */
	
	animation: eye 2.2s ease-in-out infinite, body 1.15s 1.8s linear infinite; 
} 

/* Elevate and distort the creature. */

.pojoro:hover  {
	transform: scaleY(0.9) scaleX(0.95) translateY(-3em) translateZ(0);
}

/* wings */

.pojoro:before,
.pojoro:after  {
	background: rgba(0,0,0,0);
	border-radius: 100%;
	content: "";
	
	/* display:none, hide wings */
	
	display: none;
	position: absolute;
	width: 1em; height: 0.1em;
	-webkit-filter: blur(1px);
	transition: all 0.2s;
	animation-duration: 0.2s;
	animation-iteration-count: infinite;
	animation-timing-function: ease-in-out;
}

.pojoro:before  {
	top: 25%; left: 1.45em;
	margin-left: -1em;
	transform-origin: left;
	transform: rotate(-60deg);
	animation-name: wings;
}

.pojoro:after  {
	top: 25%; left: -2.2em;
	margin-left: 1em;
	transform-origin: right;
	transform: rotate(60deg);
	animation-name: wings2;
}

.pojoro:hover:before,
.pojoro:hover:after  {
	background: rgba(100,100,100,0.8);
	
	/* display:block, we allow the wings to appear and the animation starts */
	
	display: block;
	margin-left: 0em;
	width: 2em; height: 0.3em;
}

@keyframes eye  {

	/* Eye movement */
	
	5%, 10%  {
		line-height: 1.2em;
		padding-left: 0em;
	}
	15%, 20%  {
		line-height: 1.15em;
		padding-left: 0.4em;
	}
	
	/* Eyelash movement */
	
	25%  {
		box-shadow: 0 0 0 0.2em rgb(146,89,149), 
					0 0 0.1em 0.55em rgb(166,89,169), 
					inset 0 1em 0 0 rgb(136,79,139);
	}
	23%, 27%  {
		box-shadow: 0 0 0 0.2em rgb(146,89,149), 
					0 0 0.1em 0.55em rgb(166,89,169), 
					inset 0 0.2em 0 0 rgb(136,79,139);
	}
}

@keyframes body  {
	50%  {
		width: 1.4em; height: 1.4em;
	} 
}

@keyframes wings  {
	50%  {
		transform: rotate(65deg);
	}
}

@keyframes wings2  {
	50%  {
		transform: rotate(-65deg);
	}
}
</pre>
<p>On hover we activate the wings animations and the body stars to elevate.<br />
And that was the last example!</p>
<p>In conclusion, pseudo-element are a great thing and combining them with animations and transitions allow for the creation of some fun effects without using too much markup or images. Wider browser support is hopefully coming soon; until then we can play with it and discover fun and interesting techniques.</p>
<p>What do you think about it?</p>
<p>I hope that this will be useful for you and serve as an inspiration.</p>
<h4>References</h4>
<ul>
<li><a href="http://kizu.ru/en/pseudos/">Use CSS transitions for pseudo-elements right now</a> Roman Komarov.</li>
<li><a href="http://css-tricks.com/transitions-and-animations-on-css-generated-content/">Transitions and Animations on CSS Generated Content</a> support table by Chris Coyier.</li>
<li><a href="http://stackoverflow.com/questions/5041494/manipulating-css-pseudo-elements-using-jquery-e-g-before-and-after">Manipulating CSS pseudo-elements using jQuery (e.g. :before and :after)</a> on Stackoverflow</li>
</ul>
<p><a class="demo" href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/">View demo</a> <a class="download" href="http://tympanus.net/Development/PseudoElementsAnimationsTransitions/PseudoElementsAnimationsTransitions.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/22/examples-of-pseudo-elements-animations-and-transitions/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Natural Language Form with Custom Input Elements</title>
		<link>http://tympanus.net/codrops/2013/05/21/natural-language-form-with-custom-input-elements/</link>
		<comments>http://tympanus.net/codrops/2013/05/21/natural-language-form-with-custom-input-elements/#comments</comments>
		<pubDate>Tue, 21 May 2013 15:48:09 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[natural language]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15139</guid>
		<description><![CDATA[An experimental form that uses natural language instead of the usual form display. Values are entered using custom input elements.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Tutorials/NaturalLanguageForm/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/NaturalLanguageForm2.png" alt="Natural Language Form" width="580" height="315" class="alignnone size-full wp-image-15159" /></a></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/NaturalLanguageForm/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/NaturalLanguageForm/NaturalLanguageForm.zip">Download source</a></p>
<p>There is something really interesting about <a href="http://en.wikipedia.org/wiki/Natural_language_user_interface">Natural Language UIs</a> and after visiting awesome <a href="http://escapeflight.com/">Escape Flight</a>, we wanted to play around with NL forms and custom form elements. The idea is to turn a classic form into one that uses natural language to obtain information from the user. For that we&#8217;ll construct a sentence where some words and parts are select elements and text inputs. We&#8217;ll then transform the select elements so that we can customize them.</p>
<p>Natural language forms are quite suitable for some UI cases, not for all, of course. They have a couple of limitations but they can also be more engaging for users if used in the right place and in the right way. Anyway, we wanted to give this concept a try and we&#8217;ll show you how we did it.</p>
<div class="ct-special-box"><strong>Please note: this only works as intended in browsers that support the respective CSS properties.</strong></div>
<h3>The Markup</h3>
<p>The HTML will be composed of a form with a sentence and some select and text input elements:</p>
<pre class="brush:html">
&lt;form id="nl-form" class="nl-form"&gt;
	I feel like eating 
	&lt;select&gt;
		&lt;option value="1" selected&gt;any food&lt;/option&gt;
		&lt;option value="2"&gt;Indian&lt;/option&gt;
		&lt;option value="3"&gt;French&lt;/option&gt;
		&lt;option value="4"&gt;Japanese&lt;/option&gt;
		&lt;option value="2"&gt;Italian&lt;/option&gt;
	&lt;/select&gt;
	&lt;br /&gt;in a
	&lt;select&gt;
		&lt;option value="1" selected&gt;standard&lt;/option&gt;
		&lt;option value="2"&gt;fancy&lt;/option&gt;
		&lt;option value="3"&gt;hip&lt;/option&gt;
		&lt;option value="4"&gt;traditional&lt;/option&gt;
		&lt;option value="2"&gt;fine&lt;/option&gt;
	&lt;/select&gt;
	restaurant
	&lt;select&gt;
		&lt;option value="1" selected&gt;anytime&lt;/option&gt;
	 	&lt;option value="1"&gt;at 7 p.m.&lt;/option&gt;
	 	&lt;option value="2"&gt;at 8 p.m.&lt;/option&gt;
	 	&lt;option value="3"&gt;at 9 p.m.&lt;/option&gt;
	&lt;/select&gt;
	in &lt;input type="text" value="" placeholder="any city" data-subline="For example: &lt;em&gt;Los Angeles&lt;/em&gt; or &lt;em&gt;New York&lt;/em&gt;"/&gt;
	&lt;div class="nl-submit-wrap"&gt;
		&lt;button class="nl-submit" type="submit"&gt;Find a restaurant&lt;/button&gt;
	&lt;/div&gt;
	&lt;div class="nl-overlay"&gt;&lt;/div&gt;
&lt;/form&gt;
</pre>
<p>We want to transform the select elements to a custom drop-down list, like this:</p>
<pre class="brush:html">
&lt;div class="nl-field nl-dd"&gt;
	&lt;a class="nl-field-toggle"&gt;any food&lt;/a&gt;
	&lt;ul&gt;
		&lt;li class="nl-dd-checked"&gt;any food&lt;/li&gt;
		&lt;li&gt;Indian&lt;/li&gt;
		&lt;li&gt;French&lt;/li&gt;
		&lt;li&gt;Japanese&lt;/li&gt;
		&lt;li&gt;Italian&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/NaturalLanguageForm011.png" alt="NaturalLanguageForm01" width="814" height="416" class="alignnone size-full wp-image-15161" /><br />
The toggle is the visual part in the sentence. We&#8217;ll hide the list and when we click on the toggle we want the list to appear with a nice transition. Once we click on one of the list items, we&#8217;ll replace the toggle value with the newly selected one.</p>
<p>The text input will also be transformed into a similar element:</p>
<pre class="brush:html">
&lt;div class="nl-field nl-ti-text"&gt;
	&lt;a class="nl-field-toggle"&gt;any city&lt;/a&gt;
	&lt;ul&gt;
		&lt;li class="nl-ti-input"&gt;
			&lt;input type="text" value="" placeholder="any city" /&gt;
			&lt;button class="nl-field-go"&gt;Go&lt;/button&gt;
		&lt;/li&gt;
		&lt;li class="nl-ti-example"&gt;For example: &lt;em&gt;Los Angeles&lt;/em&gt; or &lt;em&gt;New York&lt;/em&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/NaturalLanguageForm021.png" alt="NaturalLanguageForm02" width="814" height="416" class="alignnone size-full wp-image-15162" /></p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<h3>The CSS</h3>
<p><em>Note that the CSS will not contain any vendor prefixes, but you will find them in the files. Some proprietary browser rules will be listed, though.</em></p>
<p>Let&#8217;s first add some icons (checkmark and arrow):</p>
<pre class="brush:css">
@font-face {
	font-family: 'nlicons';
	src:url('../fonts/nlicons/nlicons.eot');
	src:url('../fonts/nlicons/nlicons.eot?#iefix') format('embedded-opentype'),
		url('../fonts/nlicons/nlicons.woff') format('woff'),
		url('../fonts/nlicons/nlicons.ttf') format('truetype'),
		url('../fonts/nlicons/nlicons.svg#nlicons') format('svg');
	font-weight: normal;
	font-style: normal;
}
</pre>
<p>The form will have some general styles:</p>
<pre class="brush:css">
/* general style for the form */
.nl-form {
	width: 100%;
	margin: 0.3em auto 0 auto;
	font-size: 4em;
	line-height: 1.5;
}
</pre>
<p>Let&#8217;s remove the default styling for all the lists:</p>
<pre class="brush:css">
.nl-form ul {
	list-style: none;
	margin: 0;
	padding: 0;
}
</pre>
<p>And we&#8217;ll also normalize the form elements and make them look like everything else:</p>
<pre class="brush:css">
.nl-form input,
.nl-form select,
.nl-form button {
	border: none;
	background: transparent;
	font-family: inherit;
	font-size: inherit;
	color: inherit;
	font-weight: inherit;
	line-height: inherit;
	display: inline-block;
	padding: 0;
	margin: 0;
}
</pre>
<p>We don&#8217;t want any outline on a focussed element:</p>
<pre class="brush:css">
.nl-form input:focus {
	outline: none;
}
</pre>
<p>Now, let&#8217;s take care of the custom field element. Remember, this is the custom class that we give to the transformed drop-down list and the text input element:</p>
<pre class="brush:css">
.nl-field {
	display: inline-block;
	position: relative;
}
</pre>
<p>Using <code>inline-block</code> will keep the element in the flow of our sentence.</p>
<p>When we click on the toggle, we want the whole thing to open. For that we also need to set a high z-index to the custom field:</p>
<pre class="brush:css">
.nl-field.nl-field-open {
	z-index: 10000;
}
</pre>
<p>The toggle itself, which is the visible part in the sentence, will have the following style:</p>
<pre class="brush:css">
.nl-field-toggle,
.nl-form input,
.nl-form select  {
	line-height: inherit;
	display: inline-block;
	color: #b14943;
	cursor: pointer;
	border-bottom: 1px dashed #b14943;
}
</pre>
<p>The same style we&#8217;ll apply to the default form elements if JS is disabled.</p>
<p>The unordered list will be hidden and positioned absolutely. We will use the visibility transition trick to be able to transition the opacity properly. The trick is about setting a delay for the visibility transition by default (when it disappears) and no delay when the .nl-field-open class is applied to its parent (when it appears):</p>
<pre class="brush:css">
/* drop-down list / text element */
.nl-field ul {
	position: absolute;
	visibility: hidden;
	background: #76C3BD;
	left: -0.5em;
	top: 50%;
	font-size: 80%;
	opacity: 0;
	transform: translateY(-40%) scale(0.9);
	transition: visibility 0s 0.3s, opacity 0.3s, transform 0.3s;
}

.nl-field.nl-field-open ul {
	visibility: visible;
	opacity: 1;
	transform: translateY(-50%) scale(1);
	transition: visibility 0s 0s, opacity 0.3s, transform 0.3s;
}
</pre>
<p>The style for the list elements and specifically for the ones of the drop-down are the following:</p>
<pre class="brush:css">
.nl-field ul li {
	color: #fff;
	position: relative;
}

.nl-dd ul li {
	padding: 0 1.5em 0 0.5em;
	cursor: pointer;
	white-space: nowrap;
}

.nl-dd ul li.nl-dd-checked {
	color: #478982;
}

.no-touch .nl-dd ul li:hover {
	background: rgba(0,0,0,0.05);
}

.no-touch .nl-dd ul li:hover:active {
	color: #478982;
}
</pre>
<p>Let&#8217;s define the icons for some of our elements:</p>
<pre class="brush:css">
/* icons for some elements */
.nl-dd ul li.nl-dd-checked:before,
.nl-submit:before,
.nl-field-go:before {
	font-family: 'nlicons';
	speak: none;
	font-style: normal;
	font-weight: normal;
	font-variant: normal;
	text-transform: none;
	-webkit-font-smoothing: antialiased;
}

.nl-dd ul li.nl-dd-checked:before {
	content: "\e000";
	position: absolute;
	right: 1em;
	font-size: 50%;
	line-height: 3;
}
</pre>
<p>The text input replacement field will have a minimum width:</p>
<pre class="brush:css">
.nl-ti-text ul {
	min-width: 8em;
}
</pre>
<p>The text input field, which we are still using but wrapped in our overlay field structure, will have the following style: </p>
<pre class="brush:css">
.nl-ti-text ul li.nl-ti-input input {
	width: 100%;
	padding: 0.2em 2em 0.2em 0.5em;
	border-bottom: none;
	color: #fff;
}
</pre>
<p>The arrow button will be positioned absolutely and we&#8217;ll out it on the right side:</p>
<pre class="brush:css">
.nl-form .nl-field-go {
	position: absolute;
	right: 0;
	top: 0;
	height: 100%;
	cursor: pointer;
	background: rgba(0,0,0,0.1);
	width: 1.8em;
	text-align: center;
	color: transparent;
}
</pre>
<p>The icon itself will have the following style:</p>
<pre class="brush:css">
.nl-field-go:before {
	content: "\e001";
	font-size: 75%;
	color: #fff;
	width: 100%;
	line-height: 2.5;
	display: block;
}
</pre>
<p>Let&#8217;s change the placeholder text colors to fit into the color scheme:</p>
<pre class="brush:css">
/* custom placeholder color */
input::-webkit-input-placeholder {
	color: rgba(255,255,255,0.8);
}

input:active::-webkit-input-placeholder ,
input:focus::-webkit-input-placeholder {
	color: rgba(255,255,255,0.2);
}

input::-moz-placeholder {
	color: rgba(255,255,255,0.8);
}

input:active::-moz-placeholder,
input:focus::-moz-placeholder {
	color: rgba(255,255,255,0.2);
}

input:-ms-input-placeholder {  
	color: rgba(255,255,255,0.8);
}

input:active::-ms-input-placeholder ,
input:focus::-ms-input-placeholder {
	color: rgba(255,255,255,0.2);
}
</pre>
<p>The description text item will have a smaller font size:</p>
<pre class="brush:css">
/* example field below text input */
.nl-ti-text ul li.nl-ti-example {
	font-size: 40%;
	font-style: italic;
	font-weight: 400;
	padding: 0.4em 1em;
	color: rgba(0,0,0,0.2);
	border-top: 1px dashed rgba(255,255,255,0.7);
}

.nl-ti-text ul li.nl-ti-example em {
	color: #fff
}
</pre>
<p>Let&#8217;s style the submit button and the icon:</p>
<pre class="brush:css">
.nl-submit-wrap {
	margin-top: 0.4em;
}

.nl-form .nl-submit {
	line-height: 3;
	text-transform: uppercase;
	cursor: pointer;
	position: relative;
	background: #76C3BD;
	color: #fff;
	padding: 0 1em 0 0;
	font-size: 40%;
	font-weight: bold;
	letter-spacing: 3px;
}

.nl-submit:before {
	content: "\e001";
	color: #fff;
	float: left;
	padding: 0 0.7em;
	margin: 0 0.8em 0 0;
	background: #69B1A9;
}

.no-touch .nl-form .nl-submit:hover,
.no-touch .nl-form .nl-submit:active {
	background: #69B1A9;
}

.no-touch .nl-form .nl-submit:hover:before {
	background: #58a199;
}
</pre>
<p>The overlay will be a fixed element and we&#8217;ll show it when one of the field elements are opened using the general sibling selector:</p>
<pre class="brush:css">
.nl-overlay {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0,0,0,0.5);
	opacity: 0;
	z-index: 9999;
	visibility: hidden;
	transition: visibility 0s 0.3s, opacity 0.3s;
}

.nl-field.nl-field-open ~ .nl-overlay {
	opacity: 1;
	visibility: visible;
	-webkit-transition-delay: 0s;
	-moz-transition-delay: 0s;
	transition-delay: 0s;
}
</pre>
<p>Last, but not least, let&#8217;s add some media queries for adjusting the size on smaller devices:</p>
<pre class="brush:css">
@media screen and (max-width: 45em) {
	.nl-form {
		font-size: 3em;
	}
}

@media screen and (max-width: 25em) {
	.nl-form {
		font-size: 2em;
	}
}
</pre>
<p>And that&#8217;s all the style. Now, let&#8217;s have a look at the JavaScript.</p>
<h3>The JavaScript</h3>
<p>Let&#8217;s start by defining the object representing the form element:</p>
<pre class="brush:js">
function NLForm( el ) {	
	// the form element
	this.el = el;
	// the overlay
	this.overlay = this.el.querySelector( '.nl-overlay' );
	// array with all the possible custom fields
	this.fields = [];
	// counter for each custom field
	this.fldOpen = -1;
	this._init();
}
</pre>
<p>We will start by creating some custom structure by replacing all the select and input elements inside the form. We will define a object that represents each one of these custom fields &#8211; NLField.</p>
<pre class="brush:js">
NLForm.prototype = {
	_init : function() {
		var self = this;
		Array.prototype.slice.call( this.el.querySelectorAll( 'select' ) ).forEach( function( el, i ) {
			self.fldOpen++;
			self.fields.push( new NLField( self, el, 'dropdown', self.fldOpen ) );
		} );
		Array.prototype.slice.call( this.el.querySelectorAll( 'input' ) ).forEach( function( el, i ) {
			self.fldOpen++;
			self.fields.push( new NLField( self, el, 'input', self.fldOpen ) );
		} );
	},
	...
}

function NLField( form, el, type, idx ) {
	this.form = form;
	// the original HTML element
	this.elOriginal = el;
	this.pos = idx;
	this.type = type;
	this._create();
	this._initEvents();
}
NLField.prototype = {
	_create : function() {
		if( this.type === 'dropdown' ) {
			this._createDropDown();	
		}
		else if( this.type === 'input' ) {
			this._createInput();	
		}
	},
	...
}
</pre>
<p>The structure will be different depending if it&#8217;s a select box or an input field.</p>
<pre class="brush:js">
NLField.prototype = {
	...
	_createDropDown : function() {
		var self = this;
		this.fld = document.createElement( 'div' );
		this.fld.className = 'nl-field nl-dd';
		this.toggle = document.createElement( 'a' );
		this.toggle.innerHTML = this.elOriginal.options[ this.elOriginal.selectedIndex ].innerHTML;
		this.toggle.className = 'nl-field-toggle';
		this.optionsList = document.createElement( 'ul' );
		var ihtml = '';
		Array.prototype.slice.call( this.elOriginal.querySelectorAll( 'option' ) ).forEach( function( el, i ) {
			ihtml += self.elOriginal.selectedIndex === i ? '<li class="nl-dd-checked">' + el.innerHTML + '</li>' : '<li>' + el.innerHTML + '</li>';
			// selected index value
			if( self.elOriginal.selectedIndex === i ) {
				self.selectedIdx = i;
			}
		} );
		this.optionsList.innerHTML = ihtml;
		this.fld.appendChild( this.toggle );
		this.fld.appendChild( this.optionsList );
		this.elOriginal.parentNode.insertBefore( this.fld, this.elOriginal );
		this.elOriginal.style.display = 'none';
	},
	_createInput : function() {
		var self = this;
		this.fld = document.createElement( 'div' );
		this.fld.className = 'nl-field nl-ti-text';
		this.toggle = document.createElement( 'a' );
		this.toggle.innerHTML = this.elOriginal.placeholder;
		this.toggle.className = 'nl-field-toggle';
		this.optionsList = document.createElement( 'ul' );
		this.getinput = document.createElement( 'input' );
		this.getinput.setAttribute( 'type', 'text' );
		this.getinput.placeholder = this.elOriginal.placeholder;
		this.getinputWrapper = document.createElement( 'li' );
		this.getinputWrapper.className = 'nl-ti-input';
		this.inputsubmit = document.createElement( 'button' );
		this.inputsubmit.className = 'nl-field-go';
		this.inputsubmit.innerHTML = 'Go';
		this.getinputWrapper.appendChild( this.getinput );
		this.getinputWrapper.appendChild( this.inputsubmit );
		this.example = document.createElement( 'li' );
		this.example.className = 'nl-ti-example';
		this.example.innerHTML = this.elOriginal.getAttribute( 'data-subline' );
		this.optionsList.appendChild( this.getinputWrapper );
		this.optionsList.appendChild( this.example );
		this.fld.appendChild( this.toggle );
		this.fld.appendChild( this.optionsList );
		this.elOriginal.parentNode.insertBefore( this.fld, this.elOriginal );
		this.elOriginal.style.display = 'none';
	},
	...
}
</pre>
<p>Finally we will bind some events to the custom fields. For the dropdown we want to update the form field with the value chosen from the list of options, and for the input the User will type the desired value and either press enter, the submit button or simply click the overlay to update the form value.</p>
<pre class="brush:js">
NLField.prototype = {
	...
	_initEvents : function() {
		var self = this;
		this.toggle.addEventListener( 'click', function( ev ) { ev.preventDefault(); ev.stopPropagation(); self._open(); } );
		this.toggle.addEventListener( 'touchstart', function( ev ) { ev.preventDefault(); ev.stopPropagation(); self._open(); } );

		if( this.type === 'dropdown' ) {
			var opts = Array.prototype.slice.call( this.optionsList.querySelectorAll( 'li' ) );
			opts.forEach( function( el, i ) {
				el.addEventListener( 'click', function( ev ) { ev.preventDefault(); self.close( el, opts.indexOf( el ) ); } );
				el.addEventListener( 'touchstart', function( ev ) { ev.preventDefault(); self.close( el, opts.indexOf( el ) ); } );
			} );
		}
		else if( this.type === 'input' ) {
			this.getinput.addEventListener( 'keydown', function( ev ) {
				if ( ev.keyCode == 13 ) {
					self.close();
				}
			} );
			this.inputsubmit.addEventListener( 'click', function( ev ) { ev.preventDefault(); self.close(); } );
			this.inputsubmit.addEventListener( 'touchstart', function( ev ) { ev.preventDefault(); self.close(); } );
		}

	},
	_open : function() {
		if( this.open ) {
			return false;
		}
		this.open = true;
		this.form.fldOpen = this.pos;
		var self = this;
		this.fld.className += ' nl-field-open';
	},
	close : function( opt, idx ) {
		if( !this.open ) {
			return false;
		}
		this.open = false;
		this.form.fldOpen = -1;
		this.fld.className = this.fld.className.replace(/\b nl-field-open\b/,'');

		if( this.type === 'dropdown' ) {
			if( opt ) {
				// remove class nl-dd-checked from previous option
				var selectedopt = this.optionsList.children[ this.selectedIdx ];
				selectedopt.className = '';

				opt.className = 'nl-dd-checked';
				this.toggle.innerHTML = opt.innerHTML;

				// update selected index value
				this.selectedIdx = idx;
				// update original select element´s value
				this.elOriginal.value = this.elOriginal.children[ this.selectedIdx ].value;
			}
		}
		else if( this.type === 'input' ) {
			this.getinput.blur();
			this.toggle.innerHTML = this.getinput.value.trim() !== '' ? this.getinput.value : this.getinput.placeholder;
			this.elOriginal.value = this.getinput.value;
		}
	}
	...
}
</pre>
<p>And that&#8217;s it! I hope you enjoyed this tutorial and find it inspiring! </p>
<div class="ct-github-link"><a href="https://github.com/codrops/NaturalLanguageForm">Find this project on Github</a></div>
<p><a class="demo" href="http://tympanus.net/Tutorials/NaturalLanguageForm/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/NaturalLanguageForm/NaturalLanguageForm.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/21/natural-language-form-with-custom-input-elements/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Morphing Devices</title>
		<link>http://tympanus.net/codrops/2013/05/15/morphing-devices/</link>
		<comments>http://tympanus.net/codrops/2013/05/15/morphing-devices/#comments</comments>
		<pubDate>Wed, 15 May 2013 11:52:18 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[slideshow]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15036</guid>
		<description><![CDATA[An experimental morphing devices slideshow with CSS Transitions for showcasing responsive web design screenshots. ]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/MorphingDevices/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/MorphingDevices.jpg" alt="MorphingDevices" width="580" height="315" class="alignnone size-full wp-image-15081" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/MorphingDevices/">View demo</a> <a class="download" href="http://tympanus.net/Development/MorphingDevices/MorphingDevices.zip">Download source</a></p>
<p>Today we want to share an experimental &#8220;morphing&#8221; slideshow with you. The idea is to transition between different devices that show a screenshot of a responsive website or app by applying a &#8220;device class&#8221;. By using the same elements and pseudo-elements for all the devices, we can create an interesting morph effect. We will control the classes and the switching of the image with some JavaScript. We&#8217;ve also added an option for autoplaying the slideshow and for rotating some of the devices.</p>
<div class="ct-special-box"><strong>Please note that this is very experimental and only works as intended in browsers that support the respective CSS properties.</strong></div>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/MorphingDevices_iMac.jpg" alt="MorphingDevices_iMac" width="814" height="623" class="alignnone size-full wp-image-15078" /></p>
<p>There are four devices which we will use to display different screenshots of responsive designs. Two of them, the tablet and the smartphone, can also be rotated. What we do is to interchange the classes depending on the device and since the device has transitions defined, we&#8217;ll see a morphing effect. Note that we also animate pseudo-elements here which might not be supported in all browsers (especially mobile browsers).</p>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/MorphingDevices_MacBook.jpg" alt="MorphingDevices_MacBook" width="814" height="491" class="alignnone size-full wp-image-15077" /></p>
<p>The rotation on the last two devices happens by adding another class which will rotate the device 90 degrees. </p>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/MorphingDevices_iPad.jpg" alt="MorphingDevices_iPad" width="814" height="531" class="alignnone size-full wp-image-15076" /></p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<p>The images are changed by adding the new picture and fading out the previous one. This also creates a morphing effect where the image gets stretched or squeezed to accomodate the new size. </p>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/MorphingDevices_iPhone.jpg" alt="MorphingDevices_iPhone" width="784" height="488" class="alignnone size-full wp-image-15075" /></p>
<p>The better technology to choose for this kind of effect is undoubtedly SVG, but for practicality reasons we started this experiment with CSS and JS.</p>
<p>We hope you like and enjoy it and get inspired!</p>
<div class="ct-github-link"><a href="https://github.com/codrops/MorphingDevices">Find this project on Github</a></div>
<p><a class="demo" href="http://tympanus.net/Development/MorphingDevices/">View demo</a> <a class="download" href="http://tympanus.net/Development/MorphingDevices/MorphingDevices.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/15/morphing-devices/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Responsive Retina-Ready Menu</title>
		<link>http://tympanus.net/codrops/2013/05/08/responsive-retina-ready-menu/</link>
		<comments>http://tympanus.net/codrops/2013/05/08/responsive-retina-ready-menu/#comments</comments>
		<pubDate>Wed, 08 May 2013 11:10:56 +0000</pubDate>
		<dc:creator>Stéphanie Walter</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[responsive]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=14991</guid>
		<description><![CDATA[A responsive, touch-friendly and Retina-ready menu with three layouts for different browser sizes.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Tutorials/ResponsiveRetinaReadyMenu/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/ResponsiveRetinaFriendlyMenu.jpg" alt="ResponsiveRetinaFriendlyMenu" width="580" height="315" class="alignnone size-full wp-image-15032" /></a></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/ResponsiveRetinaReadyMenu/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/ResponsiveRetinaReadyMenu/ResponsiveRetinaReadyMenu.zip">Download source</a></p>
<p>Today we will create a colorful Retina-ready and responsive menu inspired by the colors of the Maliwan manufacturer of the Borderlands game. The menu automatically changes to one of three different layouts depending on the browser window size: a &#8220;desktop&#8221; inline version, a two columns tablet-optimized version and a mobile version with a menu link to display and hide the navigation for smaller screens. To make the menu fully retina-ready, we will use an icon font so that the icons of the menu won&#8217;t get pixelized on resize.</p>
<div class="ct-special-box"><strong>Please note: some effects only work in browsers that support the respective CSS properties.</strong></div>
<h3>Preparing the icon font</h3>
<p>Creating a custom icon font might look a bit complicated, but with tools like <a href="http://icomoon.io/app/">IcoMoon</a> it&#8217;s just a matter of creating the icons and importing them into the tool. Icon fonts behave like any font, so you can easily change the color, adapt the size and it won&#8217;t get pixelized. Perfect for retina devices without having to use multiple assets for different screen resolutions.</p>
<p>The first thing we need to do is to create the icons for the menu. I use Illustrator, but any vector graphics editor like, for example Inkscape, will do. We need to create each icon and export them as a SVG file. To make sure the icon will work properly in every browser, we have to convert all lines into full objects, and merge all the objects into one big shape for each icon. Once all have been exported into nice SVG files, we can import them all into the IcoMoon App tool:</p>
<p><a href="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/icomoon-import.jpg"><img class="aligncenter size-full wp-image-14993" alt="IcoMoon import SVG" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/icomoon-import.jpg" width="580" height="160" /></a></p>
<p>We can also enhance our font with icons from the big library that IcoMoon offers. Once we have all the icons we need, we click on the &#8220;Font&#8221; button at the bottom of the page to enter the detailed settings. On this page we can choose the encoding settings for the font, and also choose if we want to assign some letters for each icon, or prefer to use the Private Use Area of the font to make sure screen readers won&#8217;t be able to output them. I recommend using the default settings that work pretty well.</p>
<p><img class="aligncenter size-full wp-image-14992" alt="Font Settings" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/font-settings.jpg" width="580" height="194" /></p>
<p>When we click on &#8220;Download&#8221; we get a ZIP file with 4 font formats (SVG, EOT, TTF and WOFF), the CSS styling and a demo page.</p>
<p>The first thing to do to be able to use the icons is to copy and paste the CSS IcoMoon provides to the top of our CSS file and make sure we also copy the font folder. There&#8217;s also <a href="http://stackoverflow.com/questions/13674808/chrome-svg-font-rendering-breaks-layout/14345363#14345363">a little &#8220;hack&#8221; to make the fonts look nicer on Chrome Windows</a> you might want to check it out.</p>
<h3>The HTML of the menu</h3>
<p>Here is what the HTML for our navigation looks like:</p>
<pre class="brush:html">&lt;nav  id="menu" class="nav"&gt;	
	&lt;ul&gt;
		&lt;li&gt;
			&lt;a  href="#" title=""&gt;
				&lt;span  class="icon"&gt; &lt;i aria-hidden="true"  class="icon-home"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;Home&lt;/span&gt;
			&lt;/a&gt;
		&lt;/li&gt;
		&lt;li&gt;		
			&lt;a href="#" title=""&gt;&lt;span class="icon"&gt; &lt;i aria-hidden="true" class="icon-services"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;Services&lt;/span&gt;&lt;/a&gt;	
		&lt;/li&gt;	
		&lt;li&gt;
			&lt;a  href="#" title=""&gt;&lt;span  class="icon"&gt;&lt;i  aria-hidden="true" class="icon-portfolio"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;Portfolio&lt;/span&gt;&lt;/a&gt;
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a  href="#" title=""&gt;&lt;span  class="icon"&gt;&lt;i  aria-hidden="true" class="icon-blog"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;Blog&lt;/span&gt;&lt;/a&gt;	
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a  href="#" title=""&gt;&lt;span  class="icon"&gt;&lt;i  aria-hidden="true" class="icon-team"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;The  team&lt;/span&gt;&lt;/a&gt;	
		&lt;/li&gt;
		&lt;li&gt;
			&lt;a  href="#" title=""&gt;&lt;span  class="icon"&gt;&lt;i  aria-hidden="true" class="icon-contact"&gt;&lt;/i&gt;&lt;/span&gt;&lt;span&gt;Contact&lt;/span&gt;&lt;/a&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;</pre>
<p>To use the icon font, we simply use the class &#8220;icon-iconname&#8221; inside an <code>i</code> element (a span will work as well). Also note that we added a <code>no-js</code> class to the body that will be changed to <code>js</code> with <a href="http://modernizr.com/">Modernizr</a>. The idea is to be able to leave the menu open if the user has JavaScript disabled. We&#8217;ll also use Modernizr to detect touch support. </p>
<h3>The CSS &amp; JavaScript</h3>
<p>Note that I won&#8217;t prefix the CSS3 properties here but you will find the prefixed version in the files. </p>
<p>The global CSS that gets applied to all screen sizes looks as follows:</p>
<pre class="brush:css">
/* Global CSS that are applied for all screen sizes */

.nav ul {
	max-width: 1240px;
	margin: 0;
	padding: 0;
	list-style: none;
	font-size: 1.5em;
	font-weight: 300;
}

.nav li span {
	display: block;
}

.nav a {
	display: block;
	color: rgba(249, 249, 249, .9);
	text-decoration: none;
	transition: color .5s, background .5s, height .5s;
}

.nav i{
	/* Make the font smoother for Chrome */
	transform: translate3d(0, 0, 0);
}

/* Remove the blue Webkit background when element is tapped */

a, button {
	-webkit-tap-highlight-color: rgba(0,0,0,0);
}

</pre>
<p>We want a first little transition on the whole navigation that lowers the opacity of all the items, except the one that is being hovered. This is the code for that:</p>
<pre class="brush:css">
/* Hover effect for the whole navigation to make the hovered item stand out */

.no-touch .nav ul:hover a {
	color: rgba(249, 249, 249, .5);
}

.no-touch .nav ul:hover a:hover {
	color: rgba(249, 249, 249, 0.99);
}
</pre>
<p>Then we want to add some nice background colors to all of the items. The code below uses a nth-child technique to select the list items. This way, you can add as many list items as you want, the color code will repeat itself.</p>
<pre class="brush:css">
.nav li:nth-child(6n+1) {
	background: rgb(208, 101, 3);
}

.nav li:nth-child(6n+2) {
	background: rgb(233, 147, 26);
}

.nav li:nth-child(6n+3) {
	background: rgb(22, 145, 190);
}

.nav li:nth-child(6n+4) {
	background: rgb(22, 107, 162);
}

.nav li:nth-child(6n+5) {
	background: rgb(27, 54, 71);
}

.nav li:nth-child(6n+6) {
	background: rgb(21, 40, 54);
}
</pre>
<p>Using a min-width media query, we can target screens that are bigger than 800px (50em, with a body font size of 15px) to transform our list into a nice horizontal navigation:</p>
<pre class="brush:css">
@media (min-width: 50em) {

	/* Transforms the list into a horizontal navigation */
	.nav li {
		float: left;
		width: 16.66666666666667%;
		text-align: center;
		transition: border .5s;
	}

	.nav a {
		display: block;
		width: auto;
	}
</pre>
<p>We continue with the nth-child selecting technique, to add a 4px border with different colors to each of our menu items. We apply it on hover, but also on focus and active to make it work on touch devices and on keyboard access.</p>
<pre class="brush:css">
	/* hover, focused and active effects that add a little colored border to the different items */

	.no-touch .nav li:nth-child(6n+1) a:hover,
	.no-touch .nav li:nth-child(6n+1) a:active,
	.no-touch .nav li:nth-child(6n+1) a:focus {
		border-bottom: 4px solid rgb(174, 78, 1);
	}

	.no-touch .nav li:nth-child(6n+2) a:hover,
	.no-touch .nav li:nth-child(6n+2) a:active,
	.no-touch .nav li:nth-child(6n+2) a:focus {
		border-bottom: 4px solid rgb(191, 117, 20);
	}

	.no-touch .nav li:nth-child(6n+3) a:hover,
	.no-touch .nav li:nth-child(6n+3) a:active,
	.no-touch .nav li:nth-child(6n+3) a:focus {
		border-bottom: 4px solid rgb(12, 110, 149);
	}

	.no-touch .nav li:nth-child(6n+4) a:hover,
	.no-touch .nav li:nth-child(6n+4) a:active,
	.no-touch .nav li:nth-child(6n+4) a:focus {
		border-bottom: 4px solid rgb(10, 75, 117);
	}

	.no-touch .nav li:nth-child(6n+5) a:hover,
	.no-touch .nav li:nth-child(6n+5) a:active,
	.no-touch .nav li:nth-child(6n+5) a:focus {
		border-bottom: 4px solid rgb(16, 34, 44);
	}

	.no-touch .nav li:nth-child(6n+6) a:hover,
	.no-touch .nav li:nth-child(6n+6) a:active,
	.no-touch .nav li:nth-child(6n+6) a:focus {
		border-bottom: 4px solid rgb(9, 18, 25);
	}
</pre>
<p>Then we place the icons and the text:</p>
<pre class="brush:css">
	/* Placing the icon */
	
	.icon {
		padding-top: 1.4em;
	}

	.icon + span {
		margin-top: 2.1em;
		transition: margin .5s;
	}
</pre>
<p>We animate the height of the elements when they are hovered:</p>
<pre class="brush:css">
	/* Animating the height of the element*/
	.nav a {
		height: 9em;
	}

	.no-touch .nav a:hover ,
	.no-touch .nav a:active ,
	.no-touch .nav a:focus {
		height: 10em;
	}	

	/* Making the text follow the height animation */
	.no-touch .nav a:hover .icon + span {
		margin-top: 3.2em;
		transition: margin .5s;
	}
</pre>
<p>Then we position the icons and prepare them for the CSS transition:</p>
<pre class="brush:css">
	/* Positioning the icons and preparing for the animation*/
	.nav i {
		position: relative;
		display: inline-block;
		margin: 0 auto;
		padding: 0.4em;
		border-radius: 50%;
		font-size: 1.8em;
		box-shadow: 0 0 0 0.8em transparent;
		background: rgba(255,255,255,0.1);
		transform: translate3d(0, 0, 0);
		transition: box-shadow .6s ease-in-out;
	}	
</pre>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<p>To give the visuel effect we want, we transition a box shadow and change its size from 0.8em to 0, and its color from transparent to some color with a high opacity. This is also where we close our first media-query.</p>
<pre class="brush:css">	
	/* Animate the box-shadow to create the effect */
	.no-touch .nav a:hover i,
	.no-touch .nav a:active i,
	.no-touch .nav a:focus i {		
		box-shadow: 0 0 0px 0px rgba(255,255,255,0.2);
		transition: box-shadow .4s ease-in-out;
	}
		
}
</pre>
<p>We set a second media query to make some little adjustments for screens between 800 and 980px:</p>
<pre class="brush:css">
@media (min-width: 50em) and (max-width: 61.250em) {

	/* Size and font adjustments to make it fit better */
	.nav ul {
		font-size: 1.2em;
	}

}
</pre>
<p>Now that we have finished the &#8220;desktop&#8221; version (with BIG quotation mark since more and more tablets now have 1024px and larger screens), we take care of the &#8220;global&#8221; CSS for screens that are smaller than 800px which equals to 49.938em here, using a max-width media query.</p>
<pre class="brush:css">/* The "tablet" and "mobile" version */

@media (max-width: 49.938em) {		
	
	/* Instead of adding a border, we transition the background color */
	.no-touch .nav ul li:nth-child(6n+1) a:hover,
	.no-touch .nav ul li:nth-child(6n+1) a:active,
	.no-touch .nav ul li:nth-child(6n+1) a:focus {
		background: rgb(227, 119, 20);
	}

	.no-touch .nav li:nth-child(6n+2) a:hover,
	.no-touch .nav li:nth-child(6n+2) a:active,
	.no-touch .nav li:nth-child(6n+2) a:focus {
		background: rgb(245, 160, 41);
	}

	.no-touch .nav li:nth-child(6n+3) a:hover,
	.no-touch .nav li:nth-child(6n+3) a:active,
	.no-touch .nav li:nth-child(6n+3) a:focus {
		background: rgb(44, 168, 219);
	}

	.no-touch .nav li:nth-child(6n+4) a:hover,
	.no-touch .nav li:nth-child(6n+4) a:active,
	.no-touch .nav li:nth-child(6n+4) a:focus {
		background: rgb(31, 120, 176);
	}

	.no-touch .nav li:nth-child(6n+5) a:hover,
	.no-touch .nav li:nth-child(6n+5) a:active,
	.no-touch .nav li:nth-child(6n+5) a:focus {
		background: rgb(39, 70, 90);
	}

	.no-touch .nav li:nth-child(6n+6) a:hover,
	.no-touch .nav li:nth-child(6n+6) a:active,
	.no-touch .nav li:nth-child(6n+6) a:focus {
		background: rgb(32, 54, 68);
	}

	.nav ul li {
		transition: background 0.5s;
	}	

}
</pre>
<p>For screen size between 520px (32.5em) and 799px (49.938em), we want to display our menu into a 2 columns and 3 rows layout. We add some padding to make the elements easy to &#8220;tap&#8221;, and display the icons on the left and the text on the right.</p>
<pre class="brush:css">
/* CSS for a 2x3 columns version */

@media (min-width: 32.5em) and (max-width: 49.938em) {
	
	/* Creating the 2 column layout using floating elements once again */
	.nav li {
		display: block;
		float: left;
		width: 50%;
	}
	
	/* Adding some padding to make the elements look nicer*/
	.nav a {
		padding: 0.8em;		
	}

	/* Displaying the icons on the left, and the text on the right side using inline-block */
	.nav li span, 
	.nav li span.icon {
		display: inline-block;
	}

	.nav li span.icon {
		width: 50%;
	}

	.nav li .icon + span {
		font-size: 1em;
	}

	.icon + span {
		position: relative;
		top: -0.2em;
	}
</pre>
<p>The animation for big screen is too complex to fit into smaller screens, so we adapt it to make it simpler and more discreet and simply animate the border. This is where we close our media query.</p>
<pre class="brush:css">	
	/* Adapting the icons to animate the size and border of the rounded background in a more discreet way */
	.nav li i {
		display: inline-block;
		padding: 8% 9%;
		border: 4px solid transparent;
		border-radius: 50%;
		font-size: 1.5em;
		background: rgba(255,255,255,0.1);
		transition: border .5s;
	}

	/* Transition effect on the border color */
	.no-touch .nav li:hover i,
	.no-touch .nav li:active i,
	.no-touch .nav li:focus i {
		border: 4px solid rgba(255,255,255,0.1);
	}

}</pre>
<p>Again, for smaller screens we adapt the font-size and width.</p>
<pre class="brush:css">
	/* Adapting the font size and width for smaller screns*/
@media (min-width: 32.5em) and (max-width: 38.688em) {
	
	.nav li span.icon {
		width: 50%;
	}

	.nav li .icon + span {
		font-size: 0.9em;
	}
}
</pre>
<p>For very small screens, we hide the navigation and display a &#8220;menu&#8221; button the user can click if he wants to display the navigation. To do this, we rely on some lines of JavaScript:</p>
<pre class="brush:js">	
//  The function to change the class
var changeClass = function (r,className1,className2) {
	var regex = new RegExp("(?:^|\\s+)" + className1 + "(?:\\s+|$)");
	if( regex.test(r.className) ) {
		r.className = r.className.replace(regex,' '+className2+' ');
    }
    else{
		r.className = r.className.replace(new RegExp("(?:^|\\s+)" + className2 + "(?:\\s+|$)"),' '+className1+' ');
    }
    return r.className;
};	

//  Creating our button for smaller screens
var menuElements = document.getElementById('menu');
menuElements.insertAdjacentHTML('afterBegin','&lt;button type="button" id="menutoggle" class="navtoogle" aria-hidden="true"&gt;&lt;i aria-hidden="true" class="icon-menu"&gt; &lt;/i&gt; Menu&lt;/button&gt;');

//  Toggle the class on click to show / hide the menu
document.getElementById('menutoggle').onclick = function() {
	changeClass(this, 'navtoogle active', 'navtoogle');
}
</pre>
<p>In order to have a cleaner HTML, I chose to create the &#8220;menu&#8221; button and insert it in the DOM using JavaScript. The function changeClass helps us to toggle the class between active and no class when the users clicks on the button.</p>
<p>Now that we have all we need for the small screen version, we can style it with CSS. The following code styles the menu button:</p>
<pre class="brush:css">
/* Styling the toggle menu link and hiding it */
.nav .navtoogle{
	display: none;	
	width: 100%;
	padding: 0.5em 0.5em 0.8em;
	font-family: 'Lato',Calibri,Arial,sans-serif;
	font-weight: normal;
	text-align: left;
	color: rgb(7, 16, 15);
	font-size: 1.2em;
	background: none;	
	border: none;
	border-bottom: 4px solid rgb(221, 221, 221);
	cursor: pointer;
}

.icon-menu {
	position: relative;
	top: 3px;
	line-height: 0;
	font-size: 1.6em;
}
</pre>
<p>By default, the menu button is hidden. We want to display it for screens smaller than 519px (<span class="brush:css">32.438em</span>):</p>
<pre class="brush:css">
@media (max-width: 32.438em) {

	/* Unhiding the styled menu link */
	.nav .navtoogle{
		margin: 0;
		display: block;
	}
</pre>
<p>We animate the height of the navigation when the button is clicked. To close the navigation, we give it a 0em height, to open it, we give it a 30em max-height. If JavaScript is not enabled, we don&#8217;t have any button, so we use the <code>no-js</code> class to always display the navigation.</p>
<pre class="brush:css">
	/* Animating the height of the navigation when the button is clicked */
	
	/* If JavaScript is disabled, the menu stays open */
	.no-js .nav ul {
		max-height: 30em;
		overflow: hidden;
	}
</pre>
<p>When JavaScript is enabled we hide the menu by default, and display it when the users clicks on the button which then gets the <code>active</code> class:</p>
<pre class="brush:css">
	/* When JavaScript is enabled, we hide the menu */
	.js .nav ul {
		max-height: 0em;
		overflow: hidden;
	}
	
	/* Displaying the menu when the user has clicked on the button */
	.js .nav .active + ul {		
		max-height: 30em;
		overflow: hidden;
		transition: max-height .4s;
	}
</pre>
<p>We adapt the layout for smaller screens, presenting the navigation in a list of items with the icon on the left and the text on the right side:</p>
<pre class="brush:css">
	/* Adapting the layout of the menu for smaller screens: icon on the left and text on the right */
	
	.nav li span {
		display: inline-block;
		height: 100%;
	}

	.nav a {
		padding: 0.5em;		
	}
	
	.icon + span {
		margin-left: 1em;
		font-size: 0.8em;
	}
</pre>
<p>We also add a 8px border on the left of each item with a nice color</p>
<pre class="brush:css">	
	/* Adding a left border of 8 px with a different color for each menu item*/
	.nav li:nth-child(6n+1) {
		border-left: 8px solid rgb(174, 78, 1);
	}

	.nav li:nth-child(6n+2) {
		border-left: 8px solid rgb(191, 117, 20);
	}

	.nav li:nth-child(6n+3) {
		border-left: 8px solid rgb(13, 111, 150);
	}

	.nav li:nth-child(6n+4) {
		border-left: 8px solid rgb(10, 75, 117);
	}

	.nav li:nth-child(6n+5) {
		border-left: 8px solid rgb(16, 34, 44);
	}

	.nav li:nth-child(6n+6) {
		border-left: 8px solid rgb(9, 18, 25);
	}
</pre>
<p>The navigation looks nice when testing its small version on desktop. But on mobile devices the items might be hard to tap. Using <a href="http://modernizr.com/download/">Modernizr</a> we can detect the touch capability of the device. If the device has touch capabilities, a <code>touch</code> class is added to the body. We can use this class to enhance the experience on touch devices and make the navigation items a little bit bigger so that the user can tap them more easily. And here we close our last media query.</p>
<pre class="brush:css">
	/* make the nav bigger on touch screens */
	.touch .nav a {
		padding: 0.8em;
	}
}
</pre>
<p>And that&#8217;s it, we&#8217;ve build a nice, touch-friendly and retina-ready navigation that works fine on desktop, tablet and mobile devices. Hope you liked it!</p>
<p><em>Image Credits: Featured image created with <a href="http://wegraphics.net/downloads/minimal-apple-product-templates/" target="_blank">Minimal Apple Product Templates from WeGraphics.net</a></em></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/ResponsiveRetinaReadyMenu/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/ResponsiveRetinaReadyMenu/ResponsiveRetinaReadyMenu.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/08/responsive-retina-ready-menu/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>A Collection of Page Transitions</title>
		<link>http://tympanus.net/codrops/2013/05/07/a-collection-of-page-transitions/</link>
		<comments>http://tympanus.net/codrops/2013/05/07/a-collection-of-page-transitions/#comments</comments>
		<pubDate>Tue, 07 May 2013 09:38:49 +0000</pubDate>
		<dc:creator>Pedro Botelho</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[page transition]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=15001</guid>
		<description><![CDATA[A showcase collection of various page transition effects using CSS animations.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/PageTransitions/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/PageTransitions.jpg" alt="A Collection of Page Transitions" width="580" height="315" class="alignnone size-full wp-image-15002" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/PageTransitions/">View demo</a> <a class="download" href="http://tympanus.net/Development/PageTransitions/PageTransitions.zip">Download source</a></p>
<p>Today we&#8217;d like to share a collection of creative page transitions with you. We&#8217;ve put together a couple of animations that could be applied to &#8220;pages&#8221; for creating interesting navigation effects when revealing a new page. While some effects are very simplistic, i.e. a simple slide movement, others make use of perspective and 3d transforms to create some depth and dynamics. </p>
<p><em>Please note that this is just for showcasing some interesting effects and for inspiration. It is not a slider or anything like that. We&#8217;ll just apply some classes to make the page transition visible, not for navigating.</em></p>
<p>The CSS animations are divided into different sets, depending on what they do.</p>
<div class="ct-special-box"><strong>Please note: this only works as intended in browsers that support the respective CSS properties.</strong></div>
<p>For showcasing the page transitions, we&#8217;ve used the following structure:</p>
<pre class="brush:html">
&lt;div id="pt-main" class="pt-perspective"&gt;
	&lt;div class="pt-page pt-page-1"&gt;
		&lt;h1&gt;&lt;span&gt;A collection of&lt;/span&gt;&lt;strong&gt;Page&lt;/strong&gt; Transitions&lt;/h1&gt;
	&lt;/div&gt;
	&lt;div class="pt-page pt-page-2"&gt;&lt;!-- ... --&gt;&lt;/div&gt;
	&lt;!-- ... --&gt;
&lt;/div&gt;
</pre>
<p>The perspective container is relative and we add a perspective of 1200px to it. The following styles are needed for all animations to work:</p>
<pre class="brush:css">
.pt-perspective {
	position: relative;
	width: 100%;
	height: 100%;
	perspective: 1200px;
	transform-style: preserve-3d;
}

.pt-page {
	width: 100%;
	height: 100%;
	position: absolute;
	top: 0;
	left: 0;
	visibility: hidden;
	overflow: hidden;
	backface-visibility: hidden;
	transform: translate3d(0, 0, 0);
}

.pt-page-current,
.no-js .pt-page {
	visibility: visible;
}

.no-js body {
	overflow: auto;
}

.pt-page-ontop {
	z-index: 999;
}
</pre>
<p>The <code>.pt-page-ontop</code> is used for some of the page transitions where we need one of the pages to stay on top of the other one.</p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<p>An example for animation classes and keyframe animations are the following ones that scale the pages in different directions and fade them in or out:</p>
<pre class="brush:css">
/* scale and fade */

.pt-page-scaleDown {
	animation: scaleDown .7s ease both;
}

.pt-page-scaleUp {
	animation: scaleUp .7s ease both;
}

.pt-page-scaleUpDown {
	animation: scaleUpDown .5s ease both;
}

.pt-page-scaleDownUp {
	animation: scaleDownUp .5s ease both;
}

.pt-page-scaleDownCenter {
	animation: scaleDownCenter .4s ease-in both;
}

.pt-page-scaleUpCenter {
	animation: scaleUpCenter .4s ease-out both;
}

/************ keyframes ************/

/* scale and fade */

@keyframes scaleDown {
	to { opacity: 0; transform: scale(.8); }
}

@keyframes scaleUp {
	from { opacity: 0; transform: scale(.8); }
}

@keyframes scaleUpDown {
	from { opacity: 0; transform: scale(1.2); }
}

@keyframes scaleDownUp {
	to { opacity: 0; transform: scale(1.2); }
}

@keyframes scaleDownCenter {
	to { opacity: 0; transform: scale(.7); }
}

@keyframes scaleUpCenter {
	from { opacity: 0; transform: scale(.7); }
}
</pre>
<p>For the purpose of this demonstration we apply the respective animation classes to the current page and the incoming one. For example:</p>
<pre class="brush:js">
//...

case 17:
	outClass = 'pt-page-scaleDown';
	inClass = 'pt-page-moveFromRight pt-page-ontop';
	break;
case 18:
	outClass = 'pt-page-scaleDown';
	inClass = 'pt-page-moveFromLeft pt-page-ontop';
	break;
case 19:
	outClass = 'pt-page-scaleDown';
	inClass = 'pt-page-moveFromBottom pt-page-ontop';
	break;

// ...
</pre>
<p>Check out the demo where you can simply iterate through the whole set of page transitions using the first button. You can also choose a specific effect from the drop-down menu. </p>
<p>I hope you enjoy this and get inspired to build some exciting things! </p>
<div class="ct-github-link"><a href="https://github.com/codrops/PageTransitions">Find this project on Github</a></div>
<p><a class="demo" href="http://tympanus.net/Development/PageTransitions/">View demo</a> <a class="download" href="http://tympanus.net/Development/PageTransitions/PageTransitions.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/07/a-collection-of-page-transitions/feed/</wfw:commentRss>
		<slash:comments>84</slash:comments>
		</item>
		<item>
		<title>Automatic Figure Numbering with CSS Counters</title>
		<link>http://tympanus.net/codrops/2013/05/02/automatic-figure-numbering-with-css-counters/</link>
		<comments>http://tympanus.net/codrops/2013/05/02/automatic-figure-numbering-with-css-counters/#comments</comments>
		<pubDate>Thu, 02 May 2013 08:39:10 +0000</pubDate>
		<dc:creator>Hugo Giraudel</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css counters]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[figure]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[images]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=14881</guid>
		<description><![CDATA[Learn about CSS counters, the figure element and how to combine both for automatically numbering figures in a web page.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/05/Automatic-Figure-Numbering-with-CSS-Counters1.jpg" alt="Automatic-Figure-Numbering-with-CSS-Counters" width="580" height="315" class="alignnone size-full wp-image-14931" /></a></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/AutomaticFigureNumbering.zip">Download source</a></p>
<p>When writing articles, blog posts, tutorials, magazine entries or anything else, you will often want to include some images, charts, photographs, or even videos and code snippets to illustrate your content.</p>
<p>That being said, you will most likely want to attach some kind of caption to these elements, and perhaps number them so your readers can keep track of your thoughts.</p>
<p>And that&#8217;s exactly what we are going to do in today&#8217;s tutorial: combining the usage of the <code>&lt;figure&gt;</code> element with CSS counters to make your inserted elements (especially images) sexy as hell!</p>
<h3>The figure element</h3>
<p>The <code>&lt;figure&gt;</code> element is intended to be used along with the <code>&lt;figcaption&gt;</code> element to mark up images, illustrations, photos, diagrams and code snippets among other things. Here is what the spec says about this element:</p>
<blockquote><p>
The figure element represents a unit of content, optionally with a caption, that is self-contained, that is typically referenced as a single unit from the main flow of the document, and that can be moved away from the main flow of the document without affecting the document&#8217;s meaning.</p>
<footer><cite><a href="http://dev.w3.org/html5/markup/figure.html">W3C Specification</a></cite></footer>
</blockquote>
<p>Here is the basic markup for a figure:</p>
<pre class="brush:html">
&lt;figure&gt;
	&lt;img src="path/to/your/image.jpg" alt="" /&gt;
	&lt;figcaption&gt;Here is the legend for your image&lt;figcaption&gt;
&lt;/figure&gt;
</pre>
<p>Here are a few notes regarding the figure element:</p>
<ul>
<li>The <code>&lt;figcaption&gt;</code> element is optional</li>
<li>You can only have one <code>&lt;figcaption&gt;</code> element in a <code>&lt;figure&gt;</code> element</li>
<li>You can embed as many other elements as you want in a <code>&lt;figure&gt;</code> element</li>
<li>When dealing with an image, you can leave the <code>alt</code> attribute empty if you include a <code>&lt;figcaption&gt;</code> to prevent screen readers from reading twice the same content</li>
</ul>
<p>For more information about the <code>&lt;figure&gt;</code> element, I recommend you <a href="http://html5doctor.com/the-figure-figcaption-elements/">this great article from HTML5Doctor</a>. There is also <a href="https://developer.mozilla.org/en-US/docs/HTML/Element/figure">this entry at Mozilla Developer Network</a> and of course <a href="http://dev.w3.org/html5/markup/figure.html">the official specification</a>.</p>
<h4>Examples</h4>
<p>For example, if you want to show a snippet of code, you can do it this way with the <code>&lt;figure&gt;</code> element:</p>
<pre class="brush:html">
&lt;figure&gt;
	&lt;code&gt;body { background: white; }&lt;/code&gt;
	&lt;figcaption&gt;Some illustrated code with figure&lt;figcaption&gt;
&lt;/figure&gt;
</pre>
<p>Basically, instead of adding your images this way:</p>
<pre class="brush:html">
<!-- This is not good enough -->
&lt;img src="cute-kitty.jpg" alt="This is a cute kitty!" /&gt;
</pre>
<p>&#8230; you can do something like this:</p>
<pre class="brush:html">
<!-- This is good and semantic -->
&lt;figure&gt;
	&lt;img src="cute-kitty.jpg" alt="" /&gt;
	&lt;figcaption&gt;This is a cute kitty!&lt;figcaption&gt;
&lt;figure&gt;
</pre>
<h4>Browser support</h4>
<p>The <code>&lt;figure&gt;</code> is part of the &#8220;new&#8221; HTML5 elements, which are not understood by a range of old browsers including Internet Explorer 8. Since you don&#8217;t want to make your layout explode because of this tutorial, I&#8217;d recommend you include a polyfill to support these elements.</p>
<p>The most known and used polyfill for HTML is <a href="https://code.google.com/p/html5shiv/">html5shiv</a> which you can embed directly from the <a href="http://html5shiv.googlecode.com/svn/trunk/html5.js">Google CDN</a> by adding this line into your files:</p>
<pre class="brush:html">&lt;!--[if IE lte 8]&gt;&lt;script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"&gt;&lt;/script&gt;&lt;![endif]--&gt;</pre>
<p>Note, how we use IE-specific conditional comments to prevent other browsers and IE versions greater than 8 from loading this script.</p>
<p>If you wish to know the story behind the html5shiv polyfill, please read <a href="http://paulirish.com/2011/the-history-of-the-html5-shiv/">this wonderful blog post from Paul Irish</a>.</p>
<h3>CSS Counters</h3>
<p>CSS Counters have to be one of the most unknown CSS properties in the whole range of properties there is. It makes automatic numbering possible exclusively through CSS, without the help of neither HTML nor JavaScript.</p>
<p>This module relies on two properties and one value:</p>
<ul>
<li><code>counter-reset</code> which is used to initialize and reset one or several counters</li>
<li><code>counter-increment</code> which is used to increment one or several counters</li>
<li><code>counter()</code> is a valid value for <code>::before</code> and <code>::after</code> pseudo-elements, accepting a counter name as parameter in order to display its value</li>
</ul>
<p>Pretty straight forward, isn&#8217;t it? Basically, you initialize a counter with the name you want to the value you want (mostly 0) and you tell a given selector to increment this counter at each occurrence. This counter can then be displayed using CSS generated content and the style and location can be specified with the <code>:before</code> and <code>:after</code> pseudo-elements.</p>
<p>The most basic implementation of a CSS counter has to be this one:</p>
<pre class="brush:css">
/* 1. We initialize the counter */
body {
	counter-reset: myAwesomeCounter;
}

/* 2. We tell each occurrence of this element to increment the counter */
.myAwesomeElement {
	counter-increment: myAwesomeCounter;
}

/* 3. We display the value of the counter before the element */
.myAwesomeElement:before {
	content: counter(myAwesomeCounter);
}
</pre>
<p><em>Note: I lied when I said &#8220;2 properties and 1 value&#8221;, there is also a <code>counters()</code> value which is almost never used. Please refer to <a href="https://developer.mozilla.org/en-US/docs/CSS/Counters">this entry at MDN</a> for more information about it.</em></p>
<h4>Example</h4>
<p>Back to our case, shall we? We want to number our images so that they are prefixed by &#8220;Fig. 1 &#8211; &#8230;&#8221;, &#8220;Fig. 2 &#8211; &#8230;&#8221; and so on, right? Let&#8217;s do it simply.</p>
<pre class="brush:css">
.article {
	counter-reset: figures;
}

.figure {
	counter-increment: figures;
}

.figure figcaption:before {
	content: 'Fig. ' counter(figures) ' - ';
}
</pre>
<p>Those 3 lines of CSS are enough to number our figures automagically. Isn&#8217;t that awesome?</p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<h3>Wrapping everything</h3>
<h4>The basics</h4>
<p>Now that we know how to use both the <code>&lt;figure&gt;</code> element and CSS Counters, it is time to make what we wanted to do: embellish our blog posts.</p>
<p>But before jumping into the code, wouldn&#8217;t it be cool if we could easily make floated or centered figures, just by adding a simple class? Sure, it would be. Let&#8217;s do this!</p>
<p>We will start by giving our figures some decent styles. Nothing too fancy, something simple and elegant enough to make a kind of frame to your images.</p>
<pre class="brush:css">
.figure {
	padding: 0.9em;
	border: 3px solid #f5bca8;
	background: #fff;
	margin: 0 auto 1em;
}
</pre>
<p>In order to horizontally center images and prevent them from breaking out of their container (the <code>&lt;figure&gt;</code> element), we need to add some rules to them (could as well be <code>&lt;video&gt;</code> or something else).</p>
<pre class="brush:css">
.figure img {
	margin: 0 auto;
	display: block;
	max-width: 100%;
}
</pre>
<p>Now the caption! We make it stand out a bit, change the typography and center it horizontally. But frankly the styling is up to you. Just remember a caption should be removed without too much hassle, so don&#8217;t write a wall of text.</p>
<pre class="brush:css">
.figure figcaption {
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 2px;
	font-size: 0.8em;
	padding: .5em;
	text-align: center;
	color: #fff;
	background: #f5bca8;
}
</pre>
<h4>Numbering</h4>
<p>Great, we still haven&#8217;t implemented the counter to number our figures. As we&#8217;ve seen in the previous section, it is very easy to do.</p>
<pre class="brush:css">
.article {
	counter-reset: figures;
}

.figure figcaption {
	counter-increment: figures;
}

.figure figcaption:before {
	content: 'Fig. ' counter(figures) ' - ';
}
</pre>
<p>If you don&#8217;t necessarily want to number your images, you can limit this to a given class on the parent element. Perhaps you&#8217;ll give your wrapper a <code>.numbered-figures</code> class so that it enables image numbering. Easy enough:</p>
<pre class="brush:css">
.numbered-figures 							{ counter-reset: figures; }
.numbered-figures .figure figcaption 		{ counter-increment: figures; }
.numbered-figures .figure figcaption:before { content: 'Fig. ' counter(figures) ' - '; }
</pre>
<h4>Variations</h4>
<p>We have the basics for our system, but we still haven&#8217;t set up a way to have floated figures across the page. We will then make two classes:</p>
<pre class="brush:css">
.figure-left {
	float: left;
	margin: 0 1em .5em 0;
	width: -webkit-min-content;
	width: -moz-min-content;
	width: min-content;
}

.figure-right {
	float: right;
	margin: 0 0 .5em 1em;
	width: -webkit-min-content;
	width: -moz-min-content;
	width: min-content;
}
</pre>
<p>For those of you who do not know <code>min-content</code>, it is a valid value for <code>width</code>, <code>min-width</code>, <code>max-width</code>, <code>height</code>, <code>min-height</code> and <code>max-height</code> among other properties include flexbox and grid layout.</p>
<p>In our case, we want the figure element to be as small as possible; basically, we want it to wrap around the image. Because <code>&lt;figure&gt;</code> is a block-level element, it stretches to the width of its parent (100%). We could set it to <code>float: left</code> or <code>display: inline-block</code> to make it collapse to the widest piece of content but if the caption happens to be wider than the image we have a problem.</p>
<p>We could hard code the width to the figure element depending on the image, but it is inflexible and non-responsive. That&#8217;s why we introduce the <code>min-content</code> value. To put it simple, it tells the <code>&lt;figure&gt;</code> element to reduce its width so that the image fits inside it perfectly even if the caption has to wrap.</p>
<p>This value is supported by Firefox 3+ with the <code>-moz-</code> prefix and Chrome 18+ with the <code>-webkit-</code> prefix. The unprefixed version is currently not supported by any browser but might be in the future so we leave it.</p>
<p>Non-supportive browsers behave as expected: no width is set, the floated <code>&lt;figure&gt;</code> element wraps around the widest element, either the image or the caption.</p>
<p><em>Note: there are other values similar to <code>min-content</code> like <code>max-content</code>, <code>fit-content</code> and <code>available</code>. Please refer to <a href="https://developer.mozilla.org/en-US/docs/CSS/width">this entry at MDN</a> or the working draft of <a href="http://www.w3.org/TR/css3-sizing/">CSS Intrinsic &amp; Extrinsic Sizing Module Level 3</a>for further information about these.</em></p>
<p>Last but not least, we need to change/remove the max-width value on images for floated figures. Either you want images to have their own size, and you need to set max-width to <code>none</code>, or you want to set a maximum width (which I recommend) and you define whatever you want:</p>
<pre class="brush:css">
.figure-right img,
.figure-left img {
	max-width: 300px; /* Adjust to suit your needs */
}
</pre>
<h4>Small screens</h4>
<p>To make sure floated figures don&#8217;t behave oddly on small screens, we need to override a couple of styles to make them full-width and horizontally centered. If you&#8217;re building your site using a mobile first approach, you&#8217;ll do it the other way but it doesn&#8217;t matter really.</p>
<pre class="brush:css">
@media (max-width: 767px) {
	.figure-left,
	.figure-right {
		float: none;
		margin: 0 0 1em 0;
		width: 100%;
	}

	.figure img {
		max-width: 100%;
	}
}
</pre>
<h4>Usage</h4>
<p>Using this is easy as a pie. Either you want an horizontally centered figure in which case you simply have to use the <code>.figure</code> class. Or &mdash; most likely &mdash; you want to float the figure either on the left or on the right in which case you have to use both the <code>.figure</code> class and a variation class (e.g <code>.figure-left</code>).</p>
<pre class="brush:html">
<!-- Horizontally centered figure -->
&lt;figure class='figure'&gt;
	&lt;img src="path/to/your/image.jpg" alt="" /&gt;
	&lt;figcaption&gt;Here is the legend for your image&lt;figcaption&gt;
&lt;/figure&gt;

<!-- Left floated figure -->
&lt;figure class='figure figure-left'&gt;
	&lt;img src="path/to/your/image.jpg" alt="" /&gt;
	&lt;figcaption&gt;Here is the legend for your image&lt;figcaption&gt;
&lt;/figure&gt;

<!-- Right floated figure -->
&lt;figure class='figure figure-right'&gt;
	&lt;img src="path/to/your/image.jpg" alt="" /&gt;
	&lt;figcaption&gt;Here is the legend for your image&lt;figcaption&gt;
&lt;/figure&gt;
</pre>
<h3>Final words</h3>
<p>That&#8217;s pretty much it guys, the only thing left to do is to implement this on your site. Please have a look at the associated <a href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/">demo</a> to see what it looks like or see it live on <a href="http://hugogiraudel.com/2013/02/04/css-gradients/">my own site</a>.</p>
<p><strong>Thanks for reading and happy coding!</strong></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/AutomaticFigureNumbering/AutomaticFigureNumbering.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/05/02/automatic-figure-numbering-with-css-counters/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Text Opening Sequence with CSS Animations</title>
		<link>http://tympanus.net/codrops/2013/04/30/text-opening-sequence-with-css-animations/</link>
		<comments>http://tympanus.net/codrops/2013/04/30/text-opening-sequence-with-css-animations/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 15:05:41 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Playground]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[typography]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=14902</guid>
		<description><![CDATA[A simple and fun text opening sequence effect with blurry letters using CSS animations.]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Development/OpeningSequence/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/04/OpeningSequence.jpg" alt="Opening Sequence" width="580" height="315" class="alignnone size-full wp-image-14905" /></a></p>
<p><a class="demo" href="http://tympanus.net/Development/OpeningSequence/">View demo</a> <a class="download" href="http://tympanus.net/Development/OpeningSequence/OpeningSequence.zip">Download source</a></p>
<p>Today I want to show you how to create a fun little typography effect with CSS animations and text shadows. Maybe you know those eerie opening sequences of movie trailers where some text is being faded in on a dark background. After seeing <a href="http://vimeo.com/64645542">Introducting Briefs</a> (which is not a terror movie trailer but a preview for an interesting app) I got inspired for recreating the effect using CSS. </p>
<p>The idea is to blur text and make it appear with a rotation while animating the space between the letters. This can be achieved in a variety of ways using properties like the new CSS filters, animating padding or margin and more. Here we&#8217;ll simply use text shadows and letter-spacing to achieve the desired effect. Since we will need to control each letter, we&#8217;ll use Dave Rupert&#8217;s <a href="http://letteringjs.com/">Lettering.js</a> to wrap the words and letters into multiple spans.</p>
<p>So, let&#8217;s do it.</p>
<div class="ct-special-box"><strong>Please note: this is highly experimental and only works as intended in browsers that support the respective CSS properties.</strong></div>
<p>The idea is to have a couple of sentences fade in with the aforementioned effect, so we&#8217;ll want to wrap every appearing bit into an <code>h2</code>:</p>
<pre class="brush:html">
&lt;div class="os-phrases"&gt;
	&lt;h2&gt;Sometimes it's better&lt;/h2&gt;
	&lt;h2&gt;to hide&lt;/h2&gt;
	&lt;h2&gt;in order to&lt;/h2&gt;
	&lt;h2&gt;survive evil&lt;/h2&gt;
	&lt;h2&gt;Thanatos&lt;/h2&gt;
	&lt;h2&gt;This fall&lt;/h2&gt;
	&lt;h2&gt;Prepare&lt;/h2&gt;
	&lt;h2&gt;Refresh to replay&lt;/h2&gt;
&lt;/div&gt;
</pre>
<p>Remember, this is just a experimental effect; let&#8217;s not be too strict with markup best practices :)</p>
<p>Now that we have the pieces of the sentences in place, let&#8217;s apply lettering to wrap every word and letter into a span. We will actually need a letter to be wrapped into two spans because we want to use perspective on each single letter. So let&#8217;s go nuts and do this:</p>
<pre class="brush:js">
$("#os-phrases > h2").lettering('words').children("span").lettering().children("span").lettering();
</pre>
<p>This will created the following insane structure: </p>
<pre class="brush:html">
&lt;div class="os-phrases" id="os-phrases"&gt;
	&lt;h2&gt;
		&lt;span class="word1"&gt;
			&lt;span class="char1"&gt;
				&lt;span class="char1"&gt;
				  S
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span class="char2"&gt;
				&lt;span class="char1"&gt;
				  o
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span class="char3"&gt;
				&lt;span class="char1"&gt;
				  m
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;!-- ... --&gt;
		&lt;/span&gt; &lt;!-- /word1 --&gt;
		&lt;!-- ... --&gt;
	&lt;/h2&gt;
	&lt;h2&gt;
		&lt;!-- ... --&gt;
	&lt;/h2&gt;
	&lt;!-- ... --&gt;
&lt;/div&gt;
</pre>
<p>We don&#8217;t really have to go that nuts but we want to be persnickety when it comes to the slight rotation: we want it to be in perspective. Rotating it without perspective will not differ too much but we want the real deal. If we are already using lettering.js we might as well go all the way.</p>
<p>Now that we&#8217;ve created a span wrapping hell, let&#8217;s make use of this mess and style the nested letters :)</p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<p><em>Note that the CSS will not contain any vendor prefixes, but you will find them in the files.</em></p>
<p>Our heading will be placed blatantly on the screen, absolutely, occupying all space:</p>
<pre class="brush:css">
.os-phrases h2 {
	font-family: 'Dosis', 'Lato', sans-serif;
	font-size: 70px;
	font-weight: 200;
	height: 100%;
	width: 100%;
	overflow: hidden;
	text-transform: uppercase;
	padding: 0;
	margin: 0;
	position: absolute;
	top: 0;
	left: 0;
	letter-spacing: 14px;
	text-align: center;
}
</pre>
<p>We want our sentences not to wrap but we want them to be centered across the screen, vertically and horizontally. How do we do that? Yes, right, we&#8217;ll abuse <a href="http://www.w3.org/TR/css3-flexbox/">flexbox</a> for that:</p>
<pre class="brush:css">
.os-phrases h2,
.os-phrases h2 > span {
	height: 100%;
	/* Centering with flexbox */
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
</pre>
<p>Note that the default value for <code>flex-wrap</code> is <code>nowrap</code> which is exactly what we want, so no need to add it here.<br />
This will center our sentence parts nicely.</p>
<p>Let&#8217;s add some space between words:</p>
<pre class="brush:css">
.os-phrases h2 > span {
	margin: 0 15px;
}
</pre>
<p>The first wrapper for a letter will have perspective:</p>
<pre class="brush:css">
.os-phrases h2 > span > span {
	display: inline-block;
	perspective: 1000px;
	transform-origin: 50% 50%;
}
</pre>
<p>The letters itself will be transparent and we&#8217;ll run an animation on them. The animation will take 5.2 seconds.</p>
<pre class="brush:css">
.os-phrases h2 > span > span > span {
	display: inline-block;
	color: hsla(0,0%,0%,0);
	transform-style: preserve-3d;
	transform: translate3d(0,0,0);
	animation: OpeningSequence 5.2s linear forwards;
}
</pre>
<p>Before we get into the animation, let&#8217;s already define the delays for the sentence parts. The 5th sentence part, the one that has our imaginary movie title &#8220;Thanatos&#8221;, will be a special one and we&#8217;ll make it take longer and appear a bit later. The 6th and 7th will follow each other more quickly. </p>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/04/OpeningSequence021.jpg" alt="OpeningSequence02" width="815" height="391" class="alignnone size-full wp-image-14909" /></p>
<pre class="brush:css">
.os-phrases h2:nth-child(2) > span > span > span {
	animation-delay: 5s;
}

.os-phrases h2:nth-child(3) > span > span > span {
	animation-delay: 10s;
}

.os-phrases h2:nth-child(4) > span > span > span {
	animation-delay: 15s;
}

.os-phrases h2:nth-child(5) > span > span > span {
	font-size: 150px;
	animation-delay: 21s;
	animation-duration: 8s;
}

.os-phrases h2:nth-child(6) > span > span > span {
	animation-delay: 30s;
}

.os-phrases h2:nth-child(7) > span > span > span {
	animation-delay: 34s;
}
</pre>
<p>And the last one? We&#8217;ll give that one a special animation, but let&#8217;s take a look at the main one first.</p>
<p>In this animation we first want the text-shadow to make the letters look very blurry. The letter spacing will be very large and the letters will be rotated on the Y-axis, so that we only see it as a slice. The opacity is 0.2. </p>
<p>Half-way through the animation, we&#8217;ll sharpen up the letters and reduce the letter spacing to 14px, increase opacity and rotate them to 0 so that we are looking right at them.</p>
<p><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/04/OpeningSequence011.jpg" alt="OpeningSequence01" width="815" height="392" class="alignnone size-full wp-image-14910" /></p>
<p>In the last step, we&#8217;ll fade the letters out and scale them up a bit, making them slightly blurry again:</p>
<pre class="brush:css">
@keyframes OpeningSequence {
	0% {
		text-shadow: 0 0 50px #fff;
		letter-spacing: 80px;
		opacity: 0.2;
		transform: rotateY(-90deg);
	}
	50% {
		text-shadow: 0 0 1px #fff;
		letter-spacing: 14px;
		opacity: 0.8;
		transform: rotateY(0deg);
	}
	85% {
		text-shadow: 0 0 1px #fff;
		opacity: 0.8;
		transform: rotateY(0deg) translateZ(100px);
	}
	100% {
		text-shadow: 0 0 10px #fff;
		opacity: 0;
		transform: translateZ(130px);
		pointer-events: none;
	}
}
</pre>
<p>Our last sentence part will have another animation, one that will simply fade it in and leave it standing there:</p>
<pre class="brush:css">
.os-phrases h2:nth-child(8) > span > span > span {
	font-size: 30px;
	animation: FadeIn 4s linear 40s forwards;
}

@keyframes FadeIn { 
	0% {
		opacity: 0;
		text-shadow: 0 0 50px #fff;
	}
	100% {
		opacity: 0.8;
		text-shadow: 0 0 1px #fff;
	}
}
</pre>
<p>Last, but not least, we&#8217;ll add some emphasis on specific words by making them bold:</p>
<pre class="brush:css">

/* Bold words */
.os-phrases h2:first-child .word3,
.os-phrases h2:nth-child(2) .word2,
.os-phrases h2:nth-child(4) .word2 {
	font-weight: 600;
}
</pre>
<p>And that&#8217;s it! I hope this was fun and inspirational!   </p>
<p><a class="demo" href="http://tympanus.net/Development/OpeningSequence/">View demo</a> <a class="download" href="http://tympanus.net/Development/OpeningSequence/OpeningSequence.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/04/30/text-opening-sequence-with-css-animations/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>Simple YouTube Menu Effect</title>
		<link>http://tympanus.net/codrops/2013/04/25/simple-youtube-menu-effect/</link>
		<comments>http://tympanus.net/codrops/2013/04/25/simple-youtube-menu-effect/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 12:08:54 +0000</pubDate>
		<dc:creator>Mary Lou</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[menu]]></category>
		<category><![CDATA[transition]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://tympanus.net/codrops/?p=14806</guid>
		<description><![CDATA[A tutorial on how to recreate the effect of YouTube's little left side menu. The idea is to slide a little menu icon to the right side while revealing some menu item list beneath. ]]></description>
				<content:encoded><![CDATA[<p><a href="http://tympanus.net/Tutorials/YouTubeLeftSideMenu/"><img src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/uploads/2013/04/YouTubeLeftSideMenu.jpg" alt="Simple YouTube Menu Effect" width="580" height="315" class="alignnone size-full wp-image-14837" /></a></p>
<p><a class="demo" href="http://tympanus.net/Tutorials/YouTubeLeftSideMenu/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/YouTubeLeftSideMenu/YouTubeLeftSideMenu.zip">Download source</a></p>
<p>Today we&#8217;ll show you how to recreate the little menu effect that you can see in the <a href="http://www.youtube.com/watch?v=_Zo8g6NWRow">left side-menu on YouTube</a> when watching a video (where it says &#8220;Guide&#8221;). The menu is made of a little menu icon, a label and a list of menu items that appears when the label or menu icon is clicked. Once it&#8217;s clicked the menu icon slides to the right and the label moves up while the list items fade in sequentially. We&#8217;ll add some more style and effects to it in order to make it a bit more interesting.</p>
<p>So, let&#8217;s do it!</p>
<h3>The Markup</h3>
<p>For the HTML we will use a <code>nav</code> element and inside we&#8217;ll add a div that will contain the menu icon and the label. We&#8217;ll use an unordered list for the menu items:</p>
<pre class="brush:html">
&lt;nav id="dr-menu" class="dr-menu"&gt;
	&lt;div class="dr-trigger"&gt;&lt;span class="dr-icon dr-icon-menu"&gt;&lt;/span&gt;&lt;a class="dr-label"&gt;Account&lt;/a&gt;&lt;/div&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-user" href="#"&gt;Xavier Densmore&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-camera" href="#"&gt;Videos&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-heart" href="#"&gt;Favorites&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-bullhorn" href="#"&gt;Subscriptions&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-download" href="#"&gt;Downloads&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-settings" href="#"&gt;Settings&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a class="dr-icon dr-icon-switch" href="#"&gt;Logout&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/nav&gt;
</pre>
<p>Each menu item will have a little icon, so we&#8217;ll give them all different classes for that. The icons that we&#8217;ll be using are from <a href="http://icomoon.io/">IcoMoon</a> and we&#8217;ve created a custom icon set with their brilliant app.</p>
<p>Let&#8217;s take a look at the CSS.</p>
<div class="ct-ad-article-wrapper ct-ad-article-wrapper-in"><div class="ct-ad-article"><img class="ct-ad-img" src="http://codropspz.tympanus.netdna-cdn.com/codrops/wp-content/themes/codropstheme02/images/advertisement.jpg" /><div id="bsap_1279993" class="bsarocks bsap_af25dfd2f1908889af7a1aa5f4dcbd9e"></div><div style="clear:both;"></div></div></div>
<h3>The CSS</h3>
<p><em>Note that the CSS will not contain any vendor prefixes, but you will find them in the files.</em></p>
<p>First, we will include our icon font:</p>
<pre class="brush:css">
@font-face {
	font-family: 'icomoon';
	src:url('../fonts/icomoon.eot');
	src:url('../fonts/icomoon.eot?#iefix') format('embedded-opentype'),
		url('../fonts/icomoon.woff') format('woff'),
		url('../fonts/icomoon.ttf') format('truetype'),
		url('../fonts/icomoon.svg#icomoon') format('svg');
	font-weight: normal;
	font-style: normal;
}
</pre>
<p>The main nav container will have some general styles, like font size, line-height, color and the dimensions. We want it to be flexible but we don&#8217;t want it to become too large or too small, so we&#8217;ll set a max-width and min-width:</p>
<pre class="brush:css">
.dr-menu {
	width: 100%;
	max-width: 400px;
	min-width: 300px;
	position: relative;
	font-size: 1.3em;
	line-height: 2.5;
	font-weight: 400;
	color: #fff;
	padding-top: 2em;
}
</pre>
<p>The division that contains the menu icon span and the label link will be positioned absolutely and we&#8217;ll set the cursor to &#8220;pointer&#8221;. It needs a high z-index to guarantee that the unordered list does not stay on top of it:</p>
<pre class="brush:css">
.dr-menu > div  {
	cursor: pointer;
	position: absolute;
	width: 100%;
	z-index: 100;
}
</pre>
<p>The menu icon span in our trigger division will also be positioned absolutely and we&#8217;ll give it a transition:</p>
<pre class="brush:css">
.dr-menu > div .dr-icon {
	top: 0;
	left: 0;
	position: absolute;
	font-size: 150%;
	line-height: 1.6;
	padding: 0 10px;
	transition: all 0.4s ease;
}
</pre>
<p>When we click on the trigger division, we will give a class called &#8220;dr-menu-open&#8221; to the nav. The menu icon will then slide to the left and we&#8217;ll also translate it for the maount of its own width so that it&#8217;s put back nicely into place without spilling over:</p>
<pre class="brush:css">
.dr-menu.dr-menu-open > div .dr-icon {
	color: #60a773;
	left: 100%;
	transform: translateX(-100%);
}
</pre>
<p>In the end of the CSS we will add our icon classes from IcoMoon. The icon in the span for the menu icon will be a bit different, and we&#8217;ll use the pseudo class :after to add the little triangle. So, let&#8217;s define that as follows:</p>
<pre class="brush:css">
.dr-menu > div .dr-icon:after {
	content: "\e008";
	position: absolute;
	font-size: 50%;
	line-height: 3.25;
	left: -10%;
	opacity: 0;
}
</pre>
<p>The icon will be absolute and we&#8217;ll pull it into place by giving it a left of -10%. The initial opacity is set to 0 because we don&#8217;t want to see it initially when the menu is closed.</p>
<p>Once we open the menu, we will want it to become visible:</p>
<pre class="brush:css">
.dr-menu.dr-menu-open > div .dr-icon:after {
	opacity: 1;
}
</pre>
<p>The label, which is an anchor in our HTML, will get some general styling and we&#8217;ll give it a padding so that it&#8217;s next to the menu icon. We&#8217;ll also add a transition because we want to animate it up, once we open the menu, which we will do by translating it on the Y-axis:</p>
<pre class="brush:css">
.dr-menu > div .dr-label {
	padding-left: 3em;
	position: relative;
	display: block;
	color: #60a773;
	font-size: 0.9em;
	font-weight: 700;
	letter-spacing: 1px;
	text-transform: uppercase;
	line-height: 2.75;
	transition: all 0.2s ease-in;
}

.dr-menu.dr-menu-open > div .dr-label {
	transform: translateY(-90%);
}
</pre>
<p>The unordered list will initially be invisible by having a opacity of 0:</p>
<pre class="brush:css">
.dr-menu ul {
	padding: 0;
	margin: 0 3em 0 0;
	list-style: none;
	opacity: 0;
	position: relative;
	z-index: 0;
	pointer-events: none;
	transition: opacity 0s linear 205ms;
}
</pre>
<p>When we open the menu we want it to get visible and a high z-index so that the trigger div does not cover it:</p>
<pre class="brush:css">
.dr-menu.dr-menu-open ul {
	opacity: 1;
	z-index: 200;
	pointer-events: auto;
	transition: opacity 0s linear 0s;
}
</pre>
<p>The two transitions are for opening and closing the menu. When we open the menu, we want it to appear immediately without a delay and when we close it, i.e. remove the class, we want that it happens with a delay. That delay is defined by the delay of the last item in the list, as we will see shortly.</p>
<p>The list items will also be invisible and we&#8217;ll set a transition for the opacity:</p>
<pre class="brush:css">
.dr-menu ul li {
	display: block;
	margin: 0 0 5px 0;
	opacity: 0;
	transition: opacity 0.3s ease;
}

.dr-menu.dr-menu-open ul li {
	opacity: 1;
}

</pre>
<p>Now, each list item will appear with a different delay: the first item will fade in immediately and the last item will appear in the end:</p>
<pre class="brush:css">

.dr-menu.dr-menu-open ul li:nth-child(2) {
	transition-delay: 35ms;
}

.dr-menu.dr-menu-open ul li:nth-child(3) {
	transition-delay: 70ms;
}

.dr-menu.dr-menu-open ul li:nth-child(4) {
	transition-delay: 105ms;
}

.dr-menu.dr-menu-open ul li:nth-child(5) {
	transition-delay: 140ms;
}

.dr-menu.dr-menu-open ul li:nth-child(6) {
	transition-delay: 175ms;
}

.dr-menu.dr-menu-open ul li:nth-child(7) {
	transition-delay: 205ms;
}
</pre>
<p>The links will have some padding and we&#8217;ll set them as inline-blocks:</p>
<pre class="brush:css">
.dr-menu ul li a {
	display: inline-block;
	padding: 0 20px;
	color: #fff;
}
</pre>
<p>And we&#8217;ll change the color on hover:</p>
<pre class="brush:css">
.dr-menu ul li a:hover {
	color: #60a773;
}
</pre>
<p>Last, but not least, let&#8217;s define the icon pseudo-elements:</p>
<pre class="brush:css">
.dr-icon:before, 
.dr-icon:after {
	position: relative;
	font-family: 'icomoon';
	speak: none;
	font-style: normal;
	font-weight: normal;
	font-variant: normal;
	text-transform: none;
	-webkit-font-smoothing: antialiased;
}

.dr-menu ul .dr-icon:before {
	margin-right: 15px;
}

.dr-icon-bullhorn:before {
	content: "\e000";
}

.dr-icon-camera:before {
	content: "\e002";
}

.dr-icon-heart:before {
	content: "\e003";
}

.dr-icon-settings:before {
	content: "\e004";
}

.dr-icon-switch:before {
	content: "\e005";
}

.dr-icon-download:before {
	content: "\e006";
}

.dr-icon-user:before {
	content: "\e001";
}

.dr-icon-menu:before {
	content: "\e007";
}
</pre>
<p>And that&#8217;s all the style. Let&#8217;s take a look at the JavaScript.</p>
<h3>The JavaScript</h3>
<p>We&#8217;ll create a small script that will take care of the menu functionality. When we click on the trigger division, we want the menu wrapper to get the class &#8220;dr-menu-open&#8221;. Since we will be animating the label out and the menu icon to the right, we want the closing to happen only when we click on the menu icon, just like in the YouTube menu:</p>
<pre class="brush:js">
var YTMenu = (function() {

	function init() {
		
		[].slice.call( document.querySelectorAll( '.dr-menu' ) ).forEach( function( el, i ) {

			var trigger = el.querySelector( 'div.dr-trigger' ),
				icon = trigger.querySelector( 'span.dr-icon-menu' ),
				open = false;

			trigger.addEventListener( 'click', function( event ) {
				if( !open ) {
					el.className += ' dr-menu-open';
					open = true;
				}
			}, false );

			icon.addEventListener( 'click', function( event ) {
				if( open ) {
					event.stopPropagation();
					open = false;
					el.className = el.className.replace(/\bdr-menu-open\b/,'');
					return false;
				}
			}, false );

		} );

	}

	init();

})();
</pre>
<p>And that&#8217;s it! I hope you enjoyed this tutorial and find it useful! </p>
<div class="ct-github-link"><a href="https://github.com/codrops/YouTubeLeftSideMenu">Find this project on Github</a></div>
<p><a class="demo" href="http://tympanus.net/Tutorials/YouTubeLeftSideMenu/">View demo</a> <a class="download" href="http://tympanus.net/Tutorials/YouTubeLeftSideMenu/YouTubeLeftSideMenu.zip">Download source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tympanus.net/codrops/2013/04/25/simple-youtube-menu-effect/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk: enhanced
Content Delivery Network via codropspz.tympanus.netdna-cdn.com

 Served from: tympanus.net @ 2013-06-18 08:51:24 by W3 Total Cache -->