<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>InsertHTML</title>
	
	<link>http://www.inserthtml.com</link>
	<description>Web Design and Development Blog</description>
	<lastBuildDate>Tue, 05 Mar 2013 22:16:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/inserthtml" /><feedburner:info uri="inserthtml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>inserthtml</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Making Custom CSS3 Video Players With HTML5 and Javascript</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/csnyqrGzw9c/</link>
		<comments>http://www.inserthtml.com/2013/03/custom-html5-video-player/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 15:33:46 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3896</guid>
		<description><![CDATA[In today&#8217;s multimedia web it&#8217;s becoming an ever increasing part of web design to include videos. Customizing the video player is one of the first things web designers think about when implementing these elements, as often the default player does not match the website, or merely for consistency across browsers and devices. In this tutorial we&#8217;re going to be going&#8230;]]></description>
				<content:encoded><![CDATA[<p>In today&#8217;s multimedia web it&#8217;s becoming an ever increasing part of web design to include videos. Customizing the video  player is one of the first things web designers think about when implementing these elements, as often the default player does not match the website, or merely for consistency across browsers and devices. In this tutorial we&#8217;re going to be going through exactly how to do that.</p>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2013/03/video.jpg" alt="Video Banner" width="600" height="300" />
</div>
<h1>The Media Element API</h1>
<p>The media element API is a simple API that allows you to manipulate videos with simple Javascript commands. For example, normally when using the HTML5 video tags we type something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;video id=&quot;our-video&quot; width=&quot;600&quot; height=&quot;400&quot; controls&gt;
    &lt;source src=&quot;movie.mp4&quot; type=&quot;video/mp4&quot;&gt;
    &lt;source src=&quot;movie-hd.mp4&quot; type=&quot;video/mp4&quot;&gt;
&lt;/video&gt;
</pre>
<p>We have set controls in the video tag so this particular video will have controls (play, pause, etc). This is all well and good but sometimes we want to control the video with another (custom) player, or maybe we just want a link that makes the video play. To do this we use the<strong> Media Elements API.</strong> For example, lets say we have something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;#&quot; class=&quot;play&quot;&gt;Click me to play the video!&lt;/a&gt;
</pre>
<p>Using the Media Elements API with jQuery we can write something as simple as this to make the video play:</p>
<pre class="brush: jscript; title: ; notranslate">
$('#our-video')[0].play();
</pre>
<div class="alert">
    We&#8217;re using [0] here so we target a specific element (in the same way that document.getElementById() works!)
</div>
<p>Easy, huh? Well it&#8217;s also possible to control a variety of video aspects with the media elements API, and you can create some pretty interesting things.</p>
<h2>Functions</h2>
<p>There are a bunch of features as part of the media elements API which can be used to control a video or how it is displayed. Here&#8217;s a bunch of things which become useful when creating a custom player:</p>
<pre class="brush: jscript; title: ; notranslate">

$('#our-video')[0].play(); // Play the video

$('#our-video')[0].pause(); // Pause the video

$('#our-video')[0].volume = 1; // Sets volume, volume ranges from 0 to 1

$('#our-video')[0].currentTime; // Current video time

$('#our-video')[0].duration; // Duration of video

$('#our-video')[0].buffered; // Amount of video buffered in seconds

if($('#our-video')[0].canPlayType('video/mp4')) { .. // If the video can play this type of format 

$('#our-video')[0].requestFullscreen; // (experimental) makes the video fullscreen
</pre>
<p>Using these simple functions and a few other tricks we&#8217;re going to combine all this to make a custom video player which you can change with just CSS.</p>
<h1>Lets Get Started</h1>
<p>First of all lets accustom ourselves with the HTML5 video tag. To create a new video element we just use the video tag. It&#8217;s best to use multiple video types since not all videos are supported by all browsers. Using just .webm and .mp4 will cover mostly every video type though.  <a href="http://www.mirovideoconverter.com/">Miro</a> provides a simple method to convert files to .webm. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;video width=&quot;600&quot; height=&quot;340&quot;&gt;
	&lt;source src=&quot;big-video.mp4&quot; type=&quot;video/mp4&quot;&gt;
	&lt;source src=&quot;movie.webm&quot; type=&quot;video/webm&quot;&gt;
&lt;/video&gt;
</pre>
<h2>The CSS</h2>
<p>CSS is what we&#8217;re going to use to style the video. This opens up a lot of possibilities since CSS is very easy to use, and changing the style of your video, therefore, becomes very easy. For this particular video style this is the CSS I&#8217;m going to be using, so go ahead and put it in your CSS file:</p>
<pre class="brush: css; title: ; notranslate">
body {
	font-size: 62.5%;
}

.player {
	background: #2a2a2a;
	box-sizing: border-box;
	border-radius: 5px;
	height: 70px;
	-moz-box-sizing: border-box;
	float: left;
	font-family: Arial, sans-serif;
	position: absolute;
	padding: 0;
	bottom: 20px;
	z-index: 2;
	opacity: 1;
	box-shadow: 0 0 10px rgba(0,0,0,0.3);
	-webkit-transition: opacity 0.3s ease-in;
	transition: opacity 0.3s ease-in;
	-moz-user-select: none;
	-webkit-user-select: none;
	user-select: none;
}

.video {
	position: relative;
}

.video:hover .player {
	opacity: 1;
}

.player .progress {
	width: 60%;
	height: 20px;
	border-radius: 5px;
	background: #676767;
	box-shadow: inset 0 -5px 10px rgba(0,0,0,0.1);
	float: left;
	cursor: pointer;
	margin: 24px 0 0 0;
	padding: 0;
	position: relative;
}

.player .progress-bar {
	background: #33b5d5;
	box-shadow: inset -30px 0px 69px -20px #89f6f5;
	border-radius: 5px;
	height: 100%;
	position: relative;
	z-index: 999;
	width: 0;
}

.player .button-holder {
	position: relative;
	left: 10px;
}

.player .progress-button {
	background: #fff;
	box-shadow: 0 0 20px rgba(0,0,0,0.3);
	border-radius: 30px;
	width: 20px;
	height: 20px;
	position: absolute;
	left: -20px;
	text-decoration: overline;
}


.player [class^=&quot;buffered&quot;] {
	background: rgba(255,255,255,0.1);
	position: absolute;
	top: 0;
	left: 30px;
	height: 100%;
	border-radius: 5px;
	z-index: 1;
}

.player .play-pause {
	display: inline-block;
	font-size: 3em;
	float: left;
	text-shadow: 0 0 0 #fff;
	color: rgba(255,255,255,0.8);
	width: 10%;
	padding: 17px 0 0 3%;
	cursor: pointer;
	font-variant: small-caps;
}

.player .play, .player .pause-button {
	-webkit-transition: all 0.2s ease-out;
}

.player .play .pause-button, .player .pause .play-button {
	display: none;
}

.player .pause-button {
	padding: 5px 2px;
	box-sizing: border-box;
	-moz-box-sizing: border-box;
	height: 34px;
}

.player .pause-button span {
	background: #fff;
	width: 8px;
	height: 24px;
	float: left;
	display: block;
}

.player .pause-button span:first-of-type {
	margin: 0 4px 0 0;
}

.player .time {
	color: #fff;
	font-weight: bold;
	font-size: 1.2em;
	position: absolute;
	right: 0;
	top: 24px;
}

.player .stime, .ttime {
	color: #444;
}
.player .play:hover {
	text-shadow: 0 0 5px #fff;
}

.player .play:active, .pause-button:active span {
	text-shadow: 0 0 7px #fff;
}


.player .pause-button:hover span {
	box-shadow: 0 0 5px #fff;
} .player .pause-button:active span {
	box-shadow: 0 0 7px #fff;
}


.player .volume {
	position: relative;
	float: left;
	width: 8%;
	margin: 0 0 0 4%;
	height: 100%;
}

.player .volume-icon {
	padding: 1.5%;
	height: 100%;
	cursor: pointer;
	box-sizing: border-box;
	-moz-box-sizing: border-box;
	-webkit-transition: all 0.15s linear;
}

.player .volume-icon-hover {
	background-color: #4f4f4f;
}

.player .volume-holder {
	height: 100px;
	width: 100%;
	background: black;
	position: absolute;
	display: none;
	background: #4f4f4f;
	left: 0;
	border-radius: 5px 5px 0 0;
	top: -100px;
}

.player .volume-bar-holder {
	background: #333;
	width: 20px;
	box-shadow: inset 0px 0px 5px rgba(0,0,0,0.3);
	margin: 15px auto;
	height: 80px;
	border-radius: 5px;
	position: relative;
	cursor: pointer;
}

.player .volume-button {
	background: #fff;
	box-shadow: 0 0 20px rgba(0,0,0,0.3);
	border-radius: 30px;
	width: 20px;
	height: 20px;
}

.player .volume-button-holder {
	position: relative;
	top: -10px;	
}

.player .volume-bar {
	background: #33b5d5;
	box-shadow: inset -30px 0px 69px -20px #89f6f5;
	border-radius: 5px;
	width: 100%;
	height: 100%;
	position: absolute;
	bottom: 0;
}

.player .fullscreen {
	width: 12%;
	cursor: pointer;
	float: left;
	height: 100%;
}

.player .fullscreen a {
	width: 25px;
	height: 20px;
	border-radius: 3px;
	background: #fff;
	display: block;
	position: relative;
	top: 23px;
	margin: 0px auto;
}

.player .volume-icon span {
	width: 20%;
	height: 13%;
	background-color: #fff;
	display: block;
	position: relative;
	z-index: 1;
	font-weight: bold;
	top: 40%;
	color: #fff;
	left: 22%;
}

.player .volume-icon span:before,
.player .volume-icon span:after {
	content: '';
	position: absolute;
}
.player .volume-icon span:before {
	width: 0;
	height: 0;
	border: 1em solid transparent;
	border-left: none;
	border-right-color: #fff;
	z-index: 2;
	top: -2px;
	left: 10%;
	margin-top: -40%;
}
.player .volume-icon span:after {
	width: 2%;
	height: 2%;
	border: 1px solid #fff;
	left: 190%;
	border-width: 0px 0px 0 0; 
	top: 5px;
	border-radius: 0 50px 0 0;
	-webkit-transform: rotate(45deg);
	-moz-transform: rotate(45deg);
	-ms-transform: rotate(45deg);
	-o-transform: rotate(45deg);
	 transform: rotate(45deg);
	 font-variant: small-caps;
 }

.player .v-change-11 span:after { border-width: 10px 10px 0 0; top: 0; }
.player .v-change-10 span:after { border-width: 9px 9px 0 0; top: 1px; }
.player .v-change-9 span:after { border-width: 8px 8px 0 0; top: 1px; }
.player .v-change-8 span:after { border-width: 7px 7px 0 0; top: 2px; }
.player .v-change-7 span:after { border-width: 6px 6px 0 0; top: 2px; }
.player .v-change-6 span:after { border-width: 5px 5px 0 0; top: 3px; }
.player .v-change-5 span:after { border-width: 4px 4px 0 0; top: 3px; }
.player .v-change-4 span:after { border-width: 3px 3px 0 0; top: 4px; }
.player .v-change-3 span:after { border-width: 2px 2px 0 0; top: 4px; }
.player .v-change-2 span:after { border-width: 1px 1px 0 0; top: 5px; }
.player .v-change-1 span:after { border-width: 0px 0px 0 0; top: 5px; }

.player .v-change-1 span:after {
	content: '+';
	-webkit-transform: rotate(45deg);
	font-size: 20px;
	top: -6px;
	left: 25px;
}
</pre>
<h2>jQuery</h2>
<p>The easiest and most succinct way to go about doing this is to use jQuery and design our code as a plugin. Don&#8217;t forget to include the <a href="http://www.jquery.com/">jQuery</a> file! As with all jQuery plugins, make a new Javascript file and paste in the following:</p>
<pre class="brush: xml; title: ; notranslate">
(function($) {

	$.fn.videoPlayer = function(options) { // videoPlayer is the name of our plugin
		
				
		var settings = {  
			playerWidth : '0.95', // Default is 95%
			videoClass : 'video'  // Video Class
		}
		
		// Extend the options so they work with the plugin
		if(options) {
			$.extend(settings, options);
		}
		
		
		// For each so that we keep chainability.
		return this.each(function() {	

                     // Code goes here

		});
	
	}
	
})(jQuery);
</pre>
<p>I&#8217;ve added a few customizable options (when you run this plugin you&#8217;ll be able to change the options to whatever you want). These include the width of the player for styling purposes (by default 0.95 or95%) and the video class (in case you need to change it because of clashes). <strong>All of our code is going to go inside the <code>return this.each(function() { });</code> brackets.</strong></p>
<p>Now the first thing we want to do is check that the video meta data is ready to run. In some cases this will take a moment to load, so if we don&#8217;t check this we&#8217;ll end up loading the video player without any data (that wouldn&#8217;t work!). We&#8217;re also going to set some basic variables, the purpose of which will become more apparent later on.</p>
<pre class="brush: jscript; title: ; notranslate">
			$(this)[0].addEventListener('loadedmetadata', function() {
			
				// Basic Variables 
				var $this = $(this);
				var $settings = settings;
				
				// Wrap the video in a div with the class of your choosing
				$this.wrap('&lt;div class=&quot;'+$settings.videoClass+'&quot;&gt;&lt;/div&gt;');
				
			
				// Select the div we just wrapped our video in for easy selection.
				var $that = $this.parent('.'+$settings.videoClass);
				
				// Some other misc variables to check when things are happening
				var $mclicking = false, 
				    $vclicking = false, 
				    $vidhover = false,
				    $volhover = false, 
				    $playing = false, 
				    $drop = false,
				    $begin = false,
				    $draggingProgess = false,
				    $storevol,	
				    x = 0, 
				    y = 0, 
				    vtime = 0, 
				    updProgWidth = 0, 
				    volume = 0;
				    


</pre>
<p>Next you want to create the structure of the player. This can be altered if you wish. We&#8217;ll also define some more variables and change the width of the player. </p>
<pre class="brush: jscript; title: ; notranslate">
				// The Structure of our video player
				{
				
				$( '&lt;div class=&quot;player&quot;&gt;'
				     + '&lt;div class=&quot;play-pause play&quot;&gt;'
				       + '&lt;span class=&quot;play-button&quot;&gt;&amp;#9658;&lt;/span&gt;'
				       + '&lt;div class=&quot;pause-button&quot;&gt;'
				         + '&lt;span&gt; &lt;/span&gt;'
					         + '&lt;span&gt; &lt;/span&gt;'
				       + '&lt;/div&gt;'
				     + '&lt;/div&gt;'
				     + '&lt;div class=&quot;progress&quot;&gt;'
				       + '&lt;div class=&quot;progress-bar&quot;&gt;'
				         + '&lt;div class=&quot;button-holder&quot;&gt;'
				           + '&lt;div class=&quot;progress-button&quot;&gt; &lt;/div&gt;'
				         + '&lt;/div&gt;'
				       + '&lt;/div&gt;'
				       + '&lt;div class=&quot;time&quot;&gt;'
				         + '&lt;span class=&quot;ctime&quot;&gt;00:00&lt;/span&gt;' 
				         + '&lt;span class=&quot;stime&quot;&gt; / &lt;/span&gt;'
				         + '&lt;span class=&quot;ttime&quot;&gt;00:00&lt;/span&gt;'
				       + '&lt;/div&gt;'
				     + '&lt;/div&gt;'
				     + '&lt;div class=&quot;volume&quot;&gt;'
				       + '&lt;div class=&quot;volume-holder&quot;&gt;'
				         + '&lt;div class=&quot;volume-bar-holder&quot;&gt;'
				           + '&lt;div class=&quot;volume-bar&quot;&gt;'
				             + '&lt;div class=&quot;volume-button-holder&quot;&gt;'	
				               + '&lt;div class=&quot;volume-button&quot;&gt; &lt;/div&gt;'
				             + '&lt;/div&gt;'
				           + '&lt;/div&gt;'
				         + '&lt;/div&gt;'
				       + '&lt;/div&gt;'
				       + '&lt;div class=&quot;volume-icon v-change-0&quot;&gt;'
				         + '&lt;span&gt; &lt;/span&gt;'
				       + '&lt;/div&gt;'
				     + '&lt;/div&gt;'
				     + '&lt;div class=&quot;fullscreen&quot;&gt; '
				       + '&lt;a href=&quot;#&quot;&gt; &lt;/a&gt;'
				     + '&lt;/div&gt;'
				   + '&lt;/div&gt;').appendTo($that);
				
				}
				
				
				// Set the width of the video
				$videoWidth = $this.width();
				$that.width($videoWidth+'px');
				
				// Set width of the player based on previously noted settings
				$that.find('.player').css({'width' : ($settings.playerWidth*100)+'%', 'left' : ((100-$settings.playerWidth*100)/2)+'%'});
				
				
				// Video information
				var $spc = $(this)[0], // Specific video
					$duration = $spc.duration, // Video Duration
					$volume = $spc.volume, // Video volume
					currentTime;

				// The width of the progress bar
				var progWidth = $that.find('.progress').width();
				
</pre>
<p>Next lets start defining some functions. The first function we&#8217;re going to define is for buffering, so the user can see what sections of the video is buffered. The second is for time setting, so the time will increase correctly. The timing function is going to be run every time the current time is updated. I&#8217;ve commented in the code so you can see exactly what is happening.</p>
<pre class="brush: jscript; title: ; notranslate">
				var bufferLength = function() {
				
					// The buffered regions of the video
					var buffered = $spc.buffered;
					
					// Rest all buffered regions everytime this function is run
					$that.find('[class^=buffered]').remove();
					
					// If buffered regions exist
					if(buffered.length &gt; 0) {
							
						// The length of the buffered regions is i
						var i = buffered.length;
							
						while(i--) {
							// Max and min buffers
							$maxBuffer = buffered.end(i);
							$minBuffer = buffered.start(i);
									
							// The offset and width of buffered area				
							var bufferOffset = ($minBuffer / $duration) * 100;			
							var bufferWidth = (($maxBuffer - $minBuffer) / $duration) * 100;
											
							// Append the buffered regions to the video
							$('&lt;div class=&quot;buffered&quot;&gt;&lt;/div&gt;').css({&quot;left&quot; : bufferOffset+'%', 'width' : bufferWidth+'%'}).appendTo($that.find('.progress'));
							
						}
					}
				} 
				
				// Run the buffer function
				bufferLength();
				
				// The timing function, updates the time.
				var timeUpdate = function($ignore) {
					
					// The current time of the video based on progress bar position
					var time = Math.round(($('.progress-bar').width() / progWidth) * $duration);
					
					// The 'real' time of the video
					var curTime = $spc.currentTime;
					
					// Seconds are set to 0 by default, minutes are the time divided by 60
					// tminutes and tseconds are the total mins and seconds.
					var seconds = 0,
						minutes = Math.floor(time / 60),
						tminutes = Math.round($duration / 60),
						tseconds = Math.round(($duration) - (tminutes*60));
					
					// If time exists (well, video time)
					if(time) {
						// seconds are equal to the time minus the minutes
						seconds = Math.round(time) - (60*minutes);
						
						// So if seconds go above 59
						if(seconds &gt; 59) {
							// Increase minutes, reset seconds
							seconds = Math.round(time) - (60*minutes);
							if(seconds == 60) {
								minutes = Math.round(time / 60); 
								seconds = 0;
							}
						}
						
					} 
					
					// Updated progress width
					updProgWidth = (curTime / $duration) * progWidth
					
					// Set a zero before the number if its less than 10.
					if(seconds &lt; 10) { seconds = '0'+seconds; }
					if(tseconds &lt; 10) { tseconds = '0'+tseconds; }
					
					// A variable set which we'll use later on
					if($ignore != true) {
						$that.find('.progress-bar').css({'width' : updProgWidth+'px'});
						$that.find('.progress-button').css({'left' : (updProgWidth-$that.find('.progress-button').width())+'px'});
					}
					
					// Update times
					$that.find('.ctime').html(minutes+':'+seconds) 
					$that.find('.ttime').html(tminutes+':'+tseconds);
				
					// If playing update buffer value
					if($spc.currentTime &gt; 0 &amp;&amp; $spc.paused == false &amp;&amp; $spc.ended == false) {
						bufferLength();
					}
					
				}
				
				// Run the timing function twice, once on init and again when the time updates.
				timeUpdate();
				$spc.addEventListener('timeupdate', timeUpdate);

</pre>
<p>Next the play button! We&#8217;re going to add and remove CSS classes to make the play change to a pause button when clicked. We&#8217;ll also set a variable to check if the video is playing, which we will use later in the code:</p>
<pre class="brush: jscript; title: ; notranslate">
				
				// When the user clicks play, bind a click event	
				$that.find('.play-pause').bind('click', function() {
					
					// Set up a playing variable
					if($spc.currentTime &gt; 0 &amp;&amp; $spc.paused == false &amp;&amp; $spc.ended == false) {
						$playing = false;
					} else { $playing = true; }
					
					// If playing, etc, change classes to show pause or play button
					if($playing == false) {
						$spc.pause();
						$(this).addClass('play').removeClass('pause');
						bufferLength();
					} else {
						$begin = true;
						$spc.play();
						$(this).addClass('pause').removeClass('play');
					} 				
					
				});

</pre>
<p>One of the most complicated parts of this code is the progress slider. First off we need to check when the user clicks on the progress bar and then set a variable telling us that&#8217;s what&#8217;s happening. Then when the user moves the mouse we&#8217;ll be able to adjust it so it slides appropriately. We&#8217;re going to use the same process for the volume slider, so I&#8217;ve included it here too, as well as an animation function for the volume icon, as well as a way to check if the user is hovering over the volume icon using the jQuery <code>hover()</code> function.</p>
<pre class="brush: jscript; title: ; notranslate">
				// Bind a function to the progress bar so the user can select a point in the video
				$that.find('.progress').bind('mousedown', function(e) {
					
					// Progress bar is being clicked
					$mclicking = true;
					
					// If video is playing then pause while we change time of the video
					if($playing == true) {
						$spc.pause();
					}
					
					// The x position of the mouse in the progress bar 
					x = e.pageX - $that.find('.progress').offset().left;
					
					// Update current time
					currentTime = (x / progWidth) * $duration;
					
					$spc.currentTime = currentTime;
					
				});
				
				// When the user clicks on the volume bar holder, initiate the volume change event
				$that.find('.volume-bar-holder').bind('mousedown', function(e) {
					
					// Clicking of volume is true
					$vclicking = true;
					
					// Y position of mouse in volume slider
					y = $that.find('.volume-bar-holder').height() - (e.pageY - $that.find('.volume-bar-holder').offset().top);
					
					// Return false if user tries to click outside volume area
					if(y &lt; 0 || y &gt; $(this).height()) {
						$vclicking = false;
						return false;
					}
					
					// Update CSS to reflect what's happened
					$that.find('.volume-bar').css({'height' : y+'px'});
					$that.find('.volume-button').css({'top' : (y-($that.find('.volume-button').height()/2))+'px'});
					 
					// Update some variables
					$spc.volume = $that.find('.volume-bar').height() / $(this).height();
					$storevol = $that.find('.volume-bar').height() / $(this).height();
					$volume = $that.find('.volume-bar').height() / $(this).height();
					
					// Run a little animation for the volume icon.
					volanim();
					
				});
				
				// A quick function for binding the animation of the volume icon
				var volanim = function() {
				
					// Check where volume is and update class depending on that.
					for(var i = 0; i &lt; 1; i += 0.1) {
									
						var fi = parseInt(Math.floor(i*10)) / 10;
						var volid = (fi * 10)+1;
						
						if($volume == 1) {
							if($volhover == true) {
								$that.find('.volume-icon').removeClass().addClass('volume-icon volume-icon-hover v-change-11');
							} else {
								$that.find('.volume-icon').removeClass().addClass('volume-icon v-change-11');
							}
						}
						else if($volume == 0) {
							if($volhover == true) {
								$that.find('.volume-icon').removeClass().addClass('volume-icon volume-icon-hover v-change-1');
							} else {
								$that.find('.volume-icon').removeClass().addClass('volume-icon v-change-1');
							}
						}
						else if($volume &gt; (fi-0.1) &amp;&amp; volume &lt; fi &amp;&amp; !$that.find('.volume-icon').hasClass('v-change-'+volid)) {
							if($volhover == true) {
								$that.find('.volume-icon').removeClass().addClass('volume-icon volume-icon-hover v-change-'+volid);	
							} else {
								$that.find('.volume-icon').removeClass().addClass('volume-icon v-change-'+volid);	
							}
						}		
						
					}
				}
				// Run the volanim function
				volanim();
				
				// Check if the user is hovering over the volume button
				$that.find('.volume').hover(function() {
					$volhover = true;
				}, function() {
					$volhover = false;
				});
				

</pre>
<p>Next we have to do the actual mouse moving event. There are a bunch of things that depend on mouse move so the function is quite long. For instance, if the user is dragging the mouse while holding the progress bar, the progress bar should slide. Similarly, so should the volume bar. On top of that, if the user is moving the mouse and the video is already playing, the player should disappear so it isn&#8217;t a distraction to the actual video. I&#8217;ve included the entire function below, commented so you can see what&#8217;s going on. I&#8217;ve also included a function that fixes a few problems with the play and pause button, so the correct icon is always displaying.</p>
<pre class="brush: jscript; title: ; notranslate">
				// For usability purposes then bind a function to the body assuming that the user has clicked mouse
				// down on the progress bar or volume bar
				$('body, html').bind('mousemove', function(e) {
					
					// Hide the player if video has been played and user hovers away from video
					if($begin == true) {
						$that.hover(function() {
							$that.find('.player').stop(true, false).animate({'opacity' : '1'}, 0.5);
						}, function() {
							$that.find('.player').stop(true, false).animate({'opacity' : '0'}, 0.5);
						});
					}
					
					// For the progress bar controls
					if($mclicking == true) {	
						
						// Dragging is happening
						$draggingProgress = true;
						// The thing we're going to apply to the CSS (changes based on conditional statements);
						var progMove = 0;
						// Width of the progress button (a little button at the end of the progress bar)
						var buttonWidth = $that.find('.progress-button').width();
						
						// Updated x posititon the user is at
						x = e.pageX - $that.find('.progress').offset().left;
						
						// If video is playing
						if($playing == true) {
							// And the current time is less than the duration				
							if(currentTime &lt; $duration) {		
								// Then the play-pause icon should definitely be a pause button 
								$that.find('.play-pause').addClass('pause').removeClass('play');
							}
						}
						
						
						if(x &lt; 0) { // If x is less than 0 then move the progress bar 0px
							progMove = 0;
							$spc.currentTime = 0;
						} 
						else if(x &gt; progWidth) { // If x is more than the progress bar width then set progMove to progWidth
							$spc.currentTime = $duration;
							progMove = progWidth;	
						}
						else { // Otherwise progMove is equal to the mouse x coordinate
							progMove = x;
							currentTime = (x / progWidth) * $duration;
							$spc.currentTime = currentTime;	
						}
						
						// Change CSS based on previous conditional statement
						$that.find('.progress-bar').css({'width' : $progMove+'px'});
						$that.find('.progress-button').css({'left' : ($progMove-buttonWidth)+'px'});
						
					}
					
					// For the volume controls
					if($vclicking == true) {	
						
						// The position of the mouse on the volume slider
						y = $that.find('.volume-bar-holder').height() - (e.pageY - $that.find('.volume-bar-holder').offset().top);
						
						// The position the user is moving to on the slider.
						var volMove = 0;
						
						// If the volume holder box is hidden then just return false
						if($that.find('.volume-holder').css('display') == 'none') {
							$vclicking = false;
							return false;
						}
						
						// Add the hover class to the volume icon
						if(!$that.find('.volume-icon').hasClass('volume-icon-hover')) {
							$that.find('.volume-icon').addClass('volume-icon-hover');
						}
						
						
						if(y &lt; 0 || y == 0) { // If y is less than 0 or equal to 0 then volMove is 0.
							
							$volume = 0; 
							volMove = 0;
							
							$that.find('.volume-icon').removeClass().addClass('volume-icon volume-icon-hover v-change-11');
							
						} else if(y &gt; $(this).find('.volume-bar-holder').height() || (y / $that.find('.volume-bar-holder').height()) == 1) { // If y is more than the height then volMove is equal to the height
							
							$volume = 1; 
							volMove = $that.find('.volume-bar-holder').height();
							
							$that.find('.volume-icon').removeClass().addClass('volume-icon volume-icon-hover v-change-1');
							
						} else { // Otherwise volMove is just y
						
							$volume = $that.find('.volume-bar').height() / $that.find('.volume-bar-holder').height();
							volMove = y;
							
						}
					
						// Adjust the CSS based on the previous conditional statmeent
						$that.find('.volume-bar').css({'height' : volMove+'px'});
						$that.find('.volume-button').css({'top' : (volMove+$that.find('.volume-button').height())+'px'});
						
						// Run the animation function
						volanim();
						
						// Change the volume and store volume
						// Store volume is the volume the user last had in place
						// in case they want to mute the video, unmuting will then
						// return the user to their previous volume.
						$spc.volume = $volume;
						$storevol = $volume;
						
						
					}
					
					// If the user hovers over the volume controls, then fade in or out the volume
					// icon hover class
					
					if($volhover == false) {
						
						$that.find('.volume-holder').stop(true, false).fadeOut(100);
						$that.find('.volume-icon').removeClass('volume-icon-hover');	
						
					}
					
					else {
						$that.find('.volume-icon').addClass('volume-icon-hover');
						$that.find('.volume-holder').fadeIn(100);			
					}
					
						
				});

				// When the video ends the play button becomes a pause button
				$spc.addEventListener('ended', function() {
					
					$playing = false;
					
					// If the user is not dragging
					if($draggingProgress == false) {
						$that.find('.play-pause').addClass('play').removeClass('pause');
					}
					
				});	

</pre>
<p>Next is a little function that checks if the user is clicking their mouse down onto the volume icon, and if so, whether to mute the video or not. We use our stored volume so we can set the volume to the previous volume should the user unmute the video.</p>
<pre class="brush: jscript; title: ; notranslate">
				// If the user clicks on the volume icon, mute the video, store previous volume, and then
				// show previous volume should they click on it again.
				$that.find('.volume-icon').bind('mousedown', function() {
					
					$volume = $spc.volume; // Update volume
					
					// If volume is undefined then the store volume is the current volume
					if(typeof $storevol == 'undefined') {
						 $storevol = $spc.volume;
					}
					
					// If volume is more than 0
					if($volume &gt; 0) {
						// then the user wants to mute the video, so volume will become 0
						$spc.volume = 0; 
						$volume = 0;
						$that.find('.volume-bar').css({'height' : '0'});
						volanim();
					}
					else {
						// Otherwise user is unmuting video, so volume is now store volume.
						$spc.volume = $storevol;
						$volume = $storevol;
						$that.find('.volume-bar').css({'height' : ($storevol*100)+'%'});
						volanim();
					}
					
					
				});
				
</pre>
<p>Next, a quick little function that resets everything when the user lets go of the mouse button:</p>
<pre class="brush: jscript; title: ; notranslate">
				
				// If the user lets go of the mouse, clicking is false for both volume and progress.
				// Also the video will begin playing if it was playing before the drag process began.
				// We're also running the bufferLength function
				$('body, html').bind('mouseup', function(e) {
					
					$mclicking = false;
					$vclicking = false;
					$draggingProgress = false;
					
					if($playing == true) {	
						$spc.play();
					}
					
					bufferLength();
					
					
				});

</pre>
<p>Finally we&#8217;re going to add a button that allows us to enable fullscreen mode. If the browser doesn&#8217;t support fullscreen the button will not be displayed, otherwise we just request it for every browser until one works.</p>
<div class="alert">
    Fullscreen is not supported by every browser. In the below example the fullscreen icon will not appear if the browser doesn&#8217;t support it.
</div>
<pre class="brush: jscript; title: ; notranslate">
				
				// Check if fullscreen supported. If it's not just don't show the fullscreen icon.
				if(!$spc.requestFullscreen &amp;&amp; !$spc.mozRequestFullScreen &amp;&amp; !$spc.webkitRequestFullScreen) {
					$('.fullscreen').hide();
				}
				
				// Requests fullscreen based on browser.
				$('.fullscreen').click(function() {
				
					if ($spc.requestFullscreen) {
						$spc.requestFullscreen();
					}
				
					else if ($spc.mozRequestFullScreen) {
						$spc.mozRequestFullScreen();
					}
					
					else if ($spc.webkitRequestFullScreen) {
						$spc.webkitRequestFullScreen();
					}
				
				});
				
				
				
			});
			
		});
	
	}
	
})(jQuery);

</pre>
<h1>Running the Plugin</h1>
<p>And we&#8217;re done! That&#8217;s all the Javascript. Save the file and include it in your HTML, then run this little bit of Javascript to make it work:</p>
<pre class="brush: jscript; title: ; notranslate">

$(document).ready(function() {
	$('video').videoPlayer({
		'playerWidth' : 0.95,
		'videoClass' : 'video'	
	});
});

</pre>
<p>And that&#8217;s it! Now it&#8217;s pretty simple to add more features to your video player via jQuery, or just change the general style of it with CSS. These features are widely supported in most browsers with the exception of fullscreen, but that will change with time. Thanks for reading and have a good day!</p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3896&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=csnyqrGzw9c:QhWo42stGO0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=csnyqrGzw9c:QhWo42stGO0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=csnyqrGzw9c:QhWo42stGO0:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=csnyqrGzw9c:QhWo42stGO0:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=csnyqrGzw9c:QhWo42stGO0:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/csnyqrGzw9c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/03/custom-html5-video-player/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/03/custom-html5-video-player/</feedburner:origLink></item>
		<item>
		<title>Experimental CSS3 Only Image Slider with 3D Transforms</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/BZPqO8a_MMs/</link>
		<comments>http://www.inserthtml.com/2013/02/css3-3d-image-slider/#comments</comments>
		<pubDate>Tue, 19 Feb 2013 16:21:09 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[css-transforms]]></category>
		<category><![CDATA[css-transitions]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[image-slider]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=4003</guid>
		<description><![CDATA[Using previously existing CSS techniques as well as new CSS3 ones, we&#8217;re going to create a pretty cool CSS only image slider with arrows and 3D transforms. To do this we&#8217;re going to use a few CSS tricks which will allow you to accomplish this. Setting up the HTML I&#8217;m sure very few people have trouble understand the core tenets&#8230;]]></description>
				<content:encoded><![CDATA[<p>Using previously existing CSS techniques as well as new CSS3 ones, we&#8217;re going to create a pretty cool CSS only image slider with arrows and 3D transforms. To do this we&#8217;re going to use a few CSS tricks which will allow you to accomplish this.</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/02/imageslider.jpg" width="600" height="300" />
</div>
<h2>Setting up the HTML</h2>
<p>I&#8217;m sure very few people have trouble understand the core tenets of HTML, so I&#8217;ll just show you the code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;slider&quot;&gt;
	&lt;input type=&quot;radio&quot; id=&quot;button-1&quot; name=&quot;controls&quot; /&gt;
	&lt;input type=&quot;radio&quot; id=&quot;button-2&quot; name=&quot;controls&quot; checked /&gt;
	&lt;input type=&quot;radio&quot; id=&quot;button-3&quot; name=&quot;controls&quot; /&gt;
	&lt;input type=&quot;radio&quot; id=&quot;button-4&quot; name=&quot;controls&quot; /&gt;
	&lt;input type=&quot;radio&quot; id=&quot;button-5&quot; name=&quot;controls&quot; /&gt;
	&lt;label for=&quot;button-1&quot; class=&quot;arrows&quot; id=&quot;arrow-1&quot;&gt;&gt;&lt;/label&gt;
	&lt;label for=&quot;button-2&quot; class=&quot;arrows&quot; id=&quot;arrow-2&quot;&lt;&gt;&lt;/label&gt;
	&lt;label for=&quot;button-3&quot; class=&quot;arrows&quot; id=&quot;arrow-3&quot;&gt;&gt;&lt;/label&gt;
	&lt;label for=&quot;button-4&quot; class=&quot;arrows&quot; id=&quot;arrow-4&quot;&gt;&gt;&lt;/label&gt;
	&lt;label for=&quot;button-5&quot; class=&quot;arrows&quot; id=&quot;arrow-5&quot;&gt;&gt;&lt;/label&gt;
	&lt;div id=&quot;slides&quot;&gt;
		&lt;div&gt;
			&lt;span id=&quot;image-1&quot;&gt; 
				&lt;span class=&quot;info&quot;&gt;
					&lt;strontg&gt;Hey, you! Get offa my cloud!&lt;/strong&gt;
					&lt;em&gt;(30 Mar)&lt;/em&gt;
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span id=&quot;image-2&quot;&gt; 
				&lt;span class=&quot;info&quot;&gt;
					&lt;strong&gt;You were always on my mind..&lt;/strong&gt;
					&lt;em&gt;(2 Jun)&lt;/em&gt;
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span id=&quot;image-3&quot;&gt;
				&lt;span class=&quot;info&quot;&gt;
					&lt;strong&gt;You know you could have it so much better, if you tried..&lt;/strong&gt;
					&lt;em&gt;(5 Aug)&lt;/em&gt;
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span id=&quot;image-4&quot;&gt; 
				&lt;span class=&quot;info&quot;&gt;
					&lt;strong&gt;Every single night, I endure the fight..&lt;/strong&gt;
					&lt;em&gt;(8 Oct)&lt;/em&gt;
				&lt;/span&gt;
			&lt;/span&gt;
			&lt;span id=&quot;image-5&quot;&gt; 
				&lt;span class=&quot;info&quot;&gt;
					&lt;strong&gt;Last night these two bouncers and one of them's alright..&lt;/strong&gt;
					&lt;em&gt;(20 Dec)&lt;/em&gt;
				&lt;/span&gt;
			&lt;/span&gt;
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;

</pre>
<p>How this works is pretty simple. We have a few form elements which we will hide, and a label that is connected to each form element. We style the labels to look like arrows, and since they are connected to form, when they are clicked the user will &#8216;check&#8217; a radio button. Then we can check if the radio button is ticked with CSS and move the image slider to the correct position using simple relative positioning.</p>
<p>The spans above with the id&#8217;s <code>image-5</code>, etc, are the slides in the image slider. We can style these directly with CSS to make them look like images or whatever we want. The content inside that (in the <code>info</code> spans) is the content that will appear when the user goes to that slide. Then we can use transitions to make everything run smoothly. </p>
<p>For this particular image slider I&#8217;m using Symbolset&#8217;s Standard icon font set (for the arrows), which you can <a href="http://symbolset.com/">download here</a> for only $30.</p>
<h2>The CSS</h2>
<p>This is the most important bit. We are using 3D transforms to create the 3D effect which are currently not supported in opera. For that reason, the user will just see a regular image slider with no 3D effects if they use opera, and this could be modified a little using jQuery if you wanted.</p>
<p>We&#8217;re using sibling selectors (tilde operator <code>∼</code>) so when the user checks the right radio button the correct image will show. The code we use for this looks a bit like this:</p>
<pre class="brush: css; title: ; notranslate">
#slider #button-1:checked ~ #slides &gt; div &gt; span { left: 5% }
</pre>
<p>So when the user checks button 1, but whole slider will move so that it is 5% from the left, and so the correct image will be shown. The rest is just pretty basic 3D transforms and transitions. Here is the entire code:</p>
<pre class="brush: css; title: ; notranslate">
body {
    margin: 0;
    padding: 0;
    background: url('ecailles.png');
    font-size: 62.5%;
}

#slider {
    display: block;
    height: 350px;
    width: 100%;
    margin: auto;
    overflow: hidden;
    margin-top: 60px;
    position: relative;
}

#slider #slides {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: Arial, sans-serif;
    position: relative;
}

#slider #slides &gt; div {
    list-style: none;
    height: 100%;
    width: 500%;
    position: relative;
    left: 0px;
    margin: 0;
    padding: 0;
    overflow: hidden;
    /* Set 3D perspective since we're using 3D transforms */
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
    -webkit-perspective: 600px; 
    -moz-perspective: 600px; 
    perspective: 600px;
    -webkit-perspective-origin: 10% 50%; 
    -moz-perspective-origin: 10% 50%; 
    perspective-origin: 10% 50%;
}

#slides &gt; div &gt; span {
	/* Run the tranistions */
	-webkit-transition: all 0.7s cubic-bezier(0.550, 0.085, 0.680, 0.530);
	-moz-transition: all 0.7s cubic-bezier(0.550, 0.085, 0.680, 0.530);
	-o-transition: all 0.7s cubic-bezier(0.550, 0.085, 0.680, 0.530);
	transition: all 0.7s cubic-bezier(0.550, 0.085, 0.680, 0.530);
	height: 320px;
	width: 10%;
	float: left;
	border-radius: 5px;
	opacity: 1;
	overflow: hidden;
	display: block;
	position: relative;
	font-size: 1.6em;
	top: 20px;
	z-index: 1;
}

/* Display none, so the user doesn't see whats happening with the radio buttons */
#slider input[type=radio] {
	display: none;
}

#slider #slides &gt; div &gt; span &gt; img {
    margin: auto;
    height: 100%;
}

/* Style the arrows so they look nice! */
#slider .arrows {
    font-size: 15px;
    color: #fff;
    position: absolute;
    top: 290px;
    display: none;
    cursor: pointer;
    font-family: &quot;SSStandard&quot;;
    z-index: 9999;
    width: 29px;
	height: 25px;
	border-radius: 32px;
	text-align: center;
	padding: 7px 0 0 3px;
    background: black;
    box-shadow: 0 0 20px rgba(200, 235, 248, 0.98), inset 0px 11px 24px -8px rgba(255,255,255,0.4);
}

#slider .arrows:hover {
	box-shadow: 0 0 20px rgba(200, 235, 248, 0.98), inset 0px -11px 24px -8px rgba(255,255,255,0.4);	
}

/* The info boxes */
#slides .info {
	width: 100%;
	padding: 20px 20px 25px 20px;
	position: relative;
	bottom: 120px;
	border-radius: 5px 5px 0 0;
	box-sizing: border-box;
	-moz-box-sizing: border-box;
	display: block;
	-webkit-transition: all 1s 0.2s cubic-bezier(1, 0, 0.6, 1);
	transition: all 1s 0.2s cubic-bezier(1, 0, 0.6, 1);
	color: #fff;
	font-weight: bold;
	background-color: rgb(30, 30, 30);
	box-shadow: 0 0 20px rgba(0,0,0,0.3);
	line-height: 30px;
}

#slides .info strong {
	border-bottom: 2px solid #fff;
	padding: 3px 0;
}

#slides .info em {
	font-size: 0.8em;
	float: right;
	padding-top: 4px;
	color: rgba(255,255,255,0.2);
}

/* This is for positioning the arrows */
#button-1:checked ~ #arrow-2, #button-2:checked ~ #arrow-3, #button-3:checked ~ #arrow-4, #button-4:checked ~ #arrow-5 {
    right: 27%;
    display: block;
}

/* Since there is no previous sibling selector in CSS, we have to select the correct arrow, reposition it and rotate it 180deg so it appears as though it's a back arrow */
#button-2:checked ~ #arrow-1, #button-3:checked ~ #arrow-2, #button-4:checked ~ #arrow-3, #button-5:checked ~ #arrow-4 {
	left: 27%;
    display: block;
    -webkit-transform: rotateZ(180deg);
    -o-transform: rotateZ(180deg);
    transform: rotateZ(180deg);
    box-shadow: 0 0 20px rgba(200, 235, 248, 0.98), inset 0px -11px 24px -8px rgba(255,255,255,0.4);
}

#button-2:checked ~ #arrow-1:hover, #button-3:checked ~ #arrow-2:hover, #button-4:checked ~ #arrow-3:hover, #button-5:checked ~ #arrow-4:hover {
    box-shadow: 0 0 20px rgba(200, 235, 248, 0.98), inset 0px 11px 24px -8px rgba(255,255,255,0.4);
}

/* The images used in the slides, feel free to change this */
#image-1 {
	background: url('1.jpg');
}

#image-2 {
	background: url('2.jpg');
}

#image-3 {
	background: url('3.jpg');
}

#image-4 {
	background: url('4.jpg');
}

#image-5 {
	background: url('5.jpg');
}

/* The next bit is a bit wordy, but it just positions the slides at either side of the selected slide 
   so we get a cool 3D effect */
#slider #button-1:checked ~ #slides &gt; div #image-2, #slider #button-1:checked ~ #slides &gt; div #image-3, 
#slider #button-1:checked ~ #slides &gt; div #image-4, #slider #button-1:checked ~ #slides &gt; div #image-5,
#slider #button-2:checked ~ #slides &gt; div #image-3, #slider #button-2:checked ~ #slides &gt; div #image-4, 
#slider #button-2:checked ~ #slides &gt; div #image-5, #slider #button-3:checked ~ #slides &gt; div #image-4,
#slider #button-3:checked ~ #slides &gt; div #image-5, #slider #button-4:checked ~ #slides &gt; div #image-5 {
	-webkit-transform: rotateY(-10deg) scale(0.8) translateX(-10%);
	transform: rotateY(-10deg) scale(0.8) translateX(-10%);
	z-index: 0;
}

#slider #button-2:checked ~ #slides &gt; div #image-1, #slider #button-3:checked ~ #slides &gt; div #image-2,
#slider #button-3:checked ~ #slides &gt; div #image-1, #slider #button-4:checked ~ #slides &gt; div #image-3, 
#slider #button-4:checked ~ #slides &gt; div #image-2, #slider #button-4:checked ~ #slides &gt; div #image-1, 
#slider #button-5:checked ~ #slides &gt; div #image-4, #slider #button-5:checked ~ #slides &gt; div #image-3,
#slider #button-5:checked ~ #slides &gt; div #image-2, #slider #button-5:checked ~ #slides &gt; div #image-1 {
	-webkit-transform: rotateY(10deg) scale(0.8) translateX(10%);
	transform: rotateY(10deg) scale(0.8) translateX(10%);
	z-index: 0;
}

/* Show the info box when the user selects the slides */
#slider #button-1:checked ~ #slides &gt; div #image-1 .info, 
#slider #button-2:checked ~ #slides &gt; div #image-2 .info,  
#slider #button-3:checked ~ #slides &gt; div #image-3 .info,
#slider #button-4:checked ~ #slides &gt; div #image-4 .info, 
#slider #button-5:checked ~ #slides &gt; div #image-5 .info {
	bottom: 0px;
}

/* .. and finally, move the slides into the correct position when the user clicks the arrow, so the right
   slide is selected */

#slider #button-1:checked ~ #slides &gt; div &gt; span { left: 5% }

#slider #button-2:checked ~ #slides &gt; div &gt; span { left: -5% }

#slider #button-3:checked ~ #slides &gt; div &gt; span { left: -15% }

#slider #button-4:checked ~ #slides &gt; div &gt; span { left: -25% }

#slider #button-5:checked ~ #slides &gt; div &gt; span { left: -35% }
</pre>
<h2>Summary</h2>
<p>This slider will work in almost all browsers (in the latest version) except opera which currently doesn&#8217;t really support 3D transforms.For opera users, though, the slider will still be functional, so this has really no effect on usability, and is more a form of graceful degradation than anything else. This kind of javascript-less slider is likely to become a lot more popular in the future, especially since it is effectively supported by all the major browser vendors. </p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=4003&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=BZPqO8a_MMs:hrmNyBv4PzQ:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=BZPqO8a_MMs:hrmNyBv4PzQ:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=BZPqO8a_MMs:hrmNyBv4PzQ:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=BZPqO8a_MMs:hrmNyBv4PzQ:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=BZPqO8a_MMs:hrmNyBv4PzQ:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/BZPqO8a_MMs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/02/css3-3d-image-slider/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/02/css3-3d-image-slider/</feedburner:origLink></item>
		<item>
		<title>What is SVG? [Guide to SVG Part 2]</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/tR3Yh472tgE/</link>
		<comments>http://www.inserthtml.com/2013/02/svg-guide-part-2/#comments</comments>
		<pubDate>Tue, 12 Feb 2013 16:54:46 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[svg]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[guide]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3936</guid>
		<description><![CDATA[In part 1 of this guide we covered all the basics from implementation structure to more advanced things such use tags. In this part we&#8217;re going to expand upon what we already know, as well as look at some of the more interesting features that SVG has. This article is part of a series! If you want to stay up&#8230;]]></description>
				<content:encoded><![CDATA[<p>In part 1 of this guide we covered all the basics from implementation structure to more advanced things such use tags. In this part we&#8217;re going to expand upon what we already know, as well as look at some of the more interesting features that SVG has.  </p>
<div class="image">
   <img  src="http://www.inserthtml.com/wp-content/uploads/2012/12/svg.gif" alt="SVG Banner Image" alt="SVG" width="600" height="300" />
</div>
<div class="alert">
    This article is part of a series! If you want to stay up to date don’t forget to follow or subscribe!
</div>
<p><a href="http://www.inserthtml.com/2013/01/svg-guide-part-1/">Part 1</a> &bull; <a href="#">Part 2</a></p>
<h2>What we will cover</h2>
<ul>
<li>Structure in depth</li>
<li>More in depth styling</li>
<li>Adding Text</li>
<li>Gradients</li>
<li>Filter Effects</li>
</ul>
<h1>Structure in-depth</h1>
<p>In the previous part of this guide we looked at some pretty neat things we can do with our SVG structure. The structure of SVG is key to understanding exactly how it works, so before we move on lets take a look at some other structural elements that SVG allows us to use.</p>
<h2>SVG inside SVG (Establishing new viewports)</h2>
<p>Sometimes, when designing something in SVG, we want to establish a new viewport. A viewport is effectively the canvas on which we draw our SVG elements. Therfore, it makes sense that the standard way to do this is to use another SVG tag inside the first SVG tag with an altered position. For example, we could do something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
    &lt;!-- Our SVG Code --&gt;
    &lt;!-- ...          --&gt;

    &lt;svg width=&quot;100&quot; height=&quot;100&quot; x=&quot;25&quot; y=&quot;25&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
        &lt;!-- This is our newly established viewport --&gt;
    &lt;/svg&gt;
&lt;/svg&gt;
</pre>
<p>The x and y attributes are where the new SVG element begins (in this example it is 25px across and 25px down). This new viewport can have its own viewBox (covered in part 1). The <code>&lt;svg></code> tag is not the only tag that defines a new viewport. The following tags do just that:</p>
<ul>
<li>SVG tag</li>
<li>Symbol tag</li>
<li>Image tag</li>
</ul>
<p>We&#8217;ve covered SVG and symbols before, but what is an image tag?</p>
<h3>The Image Tag</h3>
<p>The image tag is exactly what you expect it to be. It&#8217;s a way to add images to your SVG documents. These can be anything such as <em>png</em> or <em>jpeg</em>, or even other SVG images. They work quite similarly to images in HTML documents:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;image x=&quot;400&quot; y=&quot;400&quot; width=&quot;200px&quot; height=&quot;100px&quot; xlink:href=&quot;penguins.png&quot;&gt;
&lt;image x=&quot;50&quot; y=&quot;50&quot; width=&quot;1200px&quot; height=&quot;500px&quot; xlink:href=&quot;penguins.svg&quot;&gt;
</pre>
<h2>Conditional Statements (or the switch tag)</h2>
<p>The switch tag is pretty interesting because SVG is just a general XML based language, and conditional statements are more akin to Javascript or PHP, or even CSS more recently. Should the statement return true, the user will view the contents of the switch tag. Otherwise the contents will be hidden. The switch tag allows you to check for a few things and show SVG code accordingly:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;switch requiredFeatures=&quot;http://www.w3.org/TR/SVG11/feature#SVGDOM-animation&quot;&gt; 
   &lt;!-- The browser supports animations. The code in here will only work if the browser supports animations. You could have some animation specific code here --&gt;
&lt;/switch&gt;

&lt;switch systemLanguage=&quot;en, fr&quot;&gt;
  &lt;!-- The system language is english or french --&gt;
&lt;/switch&gt; 
</pre>
<h2>Adding Text</h2>
<p>Adding text couldn&#8217;t be easier with SVG, you just use the <code>text</code> tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;text x=&quot;0&quot; y=&quot;305&quot; fill=&quot;orange&quot; font-size=&quot;30&quot;&gt;Hello World!&lt;/text&gt;
</pre>
<p>You can even wrap text around a path, just create a path in the definitions area of your SVG document and wrap the text around that. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
   &lt;path id=&quot;mypath&quot; d=&quot;M 350,75 L 379,161 L 469,161 L 397,215 L 423,301 L 350,250 L 277,301 L 303,215 L 231,161 L 321,161 z&quot; /&gt;
&lt;/defs&gt;

&lt;text x=&quot;0&quot; y=&quot;305&quot; fill=&quot;orange&quot; font-size=&quot;30&quot;&gt;
    &lt;textPath xlink:href=&quot;#mypath&quot;&gt;Hello World!&lt;/textPath&gt;
&lt;/text&gt;

</pre>
<p>Don&#8217;t forget to include the xlink:href xmlns link in your SVG tag (since we&#8217;re using xlink:href above)! As complicated as that sounds, it just means you need to change your SVG tag from something like this: </p>
<pre class="brush: xml; title: ; notranslate">
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
</pre>
<p>to something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
</pre>
<h1>Styling SVG</h1>
<p>The main purpose of SVG is to create images, and without styles or the ability to style our SVG elements properly, SVG can seem almost pointless. For those reasons, before we move onto the more interesting things, lets take a look at styling in a little bit more detail.</p>
<p>Some of the more interesting things that SVG styling can do include:</p>
<ul>
<li>General Styles</li>
<li>Gradients</li>
<li>Filters</li>
<li>Drop Shadows</li>
<li>Text</li>
</ul>
<h2>General Styling</h2>
<p>It&#8217;s possible to style SVG elements with a simple CSS-esque style tag, most CSS tags will work, as well as a few SVG specific ones that match up with attributes (for example <code>fill: red</code> and <code>stroke: blue</code> will work, in the same way as setting the property fill=&#8221;red&#8221; and stroke=&#8221;blue&#8221; does).</p>
<pre class="brush: xml; title: ; notranslate">
&lt;rect x=&quot;100&quot; y=&quot;100&quot; width=&quot;300&quot; height=&quot;300&quot; style=&quot;background: red; border: 1px solid blue;&quot;/&gt;
</pre>
<p>Similarly, you can set style tags in your SVG and give your SVG tags classes, just like HTML!</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;style type=&quot;text/css&quot;&gt;&lt;![CDATA[
 .red {
     fill: red;
     stroke: blue;
     stroke-width: 3
}
]]&gt;&lt;/style&gt;

&lt;rect x=&quot;100&quot; y=&quot;100&quot; width=&quot;300&quot; height=&quot;300&quot; class=&quot;red&quot; /&gt;
</pre>
<h2>Gradients</h2>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/02/gradient1.jpg" alt="" /><br />
    <span>A pretty ugly gradient example</span>
</div>
<p>Gradients are a staple in modern web design, at least, for adding subtle depth to something. For that reason gradients are definable directly in SVG. Since they are definitions, we put them within def tags:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
    &lt;!-- A pretty ugly gradient --&gt;
    &lt;linearGradient id=&quot;gradient&quot;&gt;
        &lt;stop offset=&quot;10%&quot; stop-color=&quot;red&quot; /&gt;
        &lt;stop offset=&quot;90%&quot; stop-color=&quot;blue&quot; /&gt;
    &lt;/linearGradient&gt;
&lt;/defs&gt;
</pre>
<p>The stop tags represent the position the point at which the colour will begin to fade. You can add more colours or stop tags as you see fit. Since this gradient has been defined we can apply it to multiple elements just by using the url function:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;rect fill=&quot;url(#gradient)&quot; stroke=&quot;blue&quot; x=&quot;10&quot; y=&quot;25&quot; width=&quot;300&quot; height=&quot;300&quot;/&gt;
</pre>
<p>Gradients can even be applied to borders! Just change the <code>stroke="blue"</code> above to <code>stroke="url(#gradient)"</code>. If linear gradients aren&#8217;t really your thing, then perhaps a radial gradient would work instead:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
    &lt;radialGradient id=&quot;gradient&quot; gradientUnits=&quot;userSpaceOnUse&quot; cx=&quot;400&quot; cy=&quot;200&quot; r=&quot;300&quot; fx=&quot;400&quot; fy=&quot;200&quot;&gt;
        &lt;stop offset=&quot;0%&quot; stop-color=&quot;red&quot; /&gt;
        &lt;stop offset=&quot;50%&quot; stop-color=&quot;blue&quot; /&gt;
        &lt;stop offset=&quot;100%&quot; stop-color=&quot;red&quot; /&gt;
    &lt;/radialGradient&gt;
&lt;/defs&gt;

&lt;rect x=&quot;100&quot; y=&quot;100&quot; width=&quot;300&quot; height=&quot;300&quot; fill=&quot;url(#gradient)&quot; /&gt;

</pre>
<p>There are a few attributes associated with the radial gradient which might make you look twice:</p>
<ul>
<li><strong>gradientUnits</strong> &#8211; (can be userSpaceOnUse or objectBoundingBox) Determines how the stop tag offsets will work (i.e. what coordinating system they will use). So for example, if it&#8217;s set to userSpaceOnUse the units used will be mapped to the element you apply it to. If you set it to objectBoundingBox it will use its bounding box (i.e. the smallest area the gradient can fit into) as its coordinate system. </li>
<li><strong>cx, cy</strong> &#8211; The center of the radial gradient </li>
<li><strong>fx, fy</strong> &#8211; The focal point. Effectively the gradient is drawn in such a way so that the offset=&#8221;0%&#8221; at this point</li>
</ul>
<h2>Filters</h2>
<p>Perhaps one of the most interesting ways to style your SVG elements is to use filters. Filters are similar to gradients, in that they are defined and can be reused, but the filter module is huge and provide many complicated ways to change how SVG elements are defined. Filters can become quite complicated and have a very specialized vocabulary of tags, but learning them is key to styling SVG. Most filters begin with a filter tag inside the usual <code>&lt;defs></code> tag. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
    &lt;filter id=&quot;filter&quot; primitiveUnits=&quot;userSpaceOnUse&quot; x=&quot;0&quot; y=&quot;0&quot; width=&quot;200&quot; height=&quot;120&quot;&gt;

    &lt;/filter&gt;
&lt;/defs&gt;
</pre>
<p>That seems pretty simple, but it&#8217;s the stuff that goes into the filter that makes it important, and there are <em>a lot</em> of filter tags, each of which accomplish something different. Before we get to that though, there are a few things we should cover. Filters generally follow a set syntax, and some of the most common attributes are <code>in</code> and <code>result</code>. </p>
<div class="alert">
    It&#8217;s important to note when filtering we are filtering an aspect of something. This aspect may encompass the whole element (i.e. the graphic in an image tag) but that is not necessarily the case.
</div>
<p>The <strong>in</strong> attribute is what you&#8217;re trying to filter. When we finish our filter we will apply it to a block element such as an image or a <code>&lt;g></code> tag, and this is what we want the in attribute to represent. In total there are 4 aspects of an element we can filter (there are more but they aren&#8217;t widely supported). </p>
<ul>
<li><strong>SourceGraphic</strong> &#8211; The graphic/image of the element we are applying our filters to. If there is no graphic/image then this will return as just black (nothing will happen basically)</li>
<li><strong>SourceAlpha</strong> &#8211; The alpha channels for the element we are applying our filters to. Again, if there are none this will return black.</li>
<li><strong>FillPaint</strong> &#8211; The contents of the fill tag. Often this is pretty useless to use, but it might be useful if the fill was a gradient or something.</li>
<li><strong>StrokePaint</strong> &#8211; The contents of the stroke tag. Again, usually quite useless.</li>
<li><strong>Contents of the <em>result</em> attribute</strong> &#8211; This is where the result attribute comes in. It&#8217;s effectively an identifier for the output. <strong>Think of filters like a machine. You put something into one component of the machine, and when it comes out you can place it in another component</strong>. So when your filtered element comes out of the first filter, you can identify it with the result attribute and then use it inside the <code>in</code> tag.
</ul>
<h3>An example of the in/result mechanism</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- obviously the filter is not called 'thefilter', 
     we'll cover filter types straight after this. --&gt;

&lt;!-- for the first filter we just use the SourceGraphic, 
     that is the image or graphic of the element we're filtering.
     the result of this is called 'myfirstfilter --&gt;

&lt;thefilter in=&quot;SourceGraphic&quot; result=&quot;myfirstfilter&quot; /&gt; 

&lt;!-- we can then use 'myfirstfilter' as the base of our next filter
     i.e. we take our first filter and filter it again with another
     filter --&gt;
&lt;thefilter in=&quot;myfirstfilter&quot; /&gt;&lt;/li&gt; 
</pre>
<h2>Applying filters</h2>
<p>Filters are applied to elements in SVG. You define a filter, and then it can be used on multiple elements. To apply a filter in SVG you simply use the filter tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;g filter=&quot;url(#filterid)&quot;&gt;
   ...
&lt;/g&gt; 
</pre>
<p><code>#filterid</code> being the id you applied to the filter (obviously!).</p>
<h2>Filter list</h2>
<p>The following titles are the tag names in question. There are a lot of filters and the art of filtering could take a while to truly master.</p>
<h3>feBlend</h3>
<p>Takes two images and blends them using common blending modes in image software. It has two &#8216;in&#8217; inputs for this reason. This is quite useful to use in conjunction with <code>feImage</code> (see further below for more info on feImage). </p>
<p>There are 6 blend modes, those being normal, multiply, screen, darken and lighten. Here&#8217;s an example:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;blendmode&quot;&gt;
   &lt;feImage xlink:href=&quot;image.jpg&quot; result=&quot;myimage&quot; /&gt;
   &lt;feBlend mode=&quot;screen&quot; in=&quot;SourceGraphic&quot; in2=&quot;myimage&quot; /&gt;
&lt;/filter&gt;
</pre>
<p>So in the above example we&#8217;re using the source graphic (the graphic of the element we&#8217;re going to apply the filter to) and the image we linked to using feImage, via the result tag. Of course, you can alter the filter blend tag to whatever blend mode you want.</p>
<h3>feColorMatrix</h3>
<p><code>feColorMatrix</code> provides ways to modify or filter an object using a matrix. There are a few default settings too so if you&#8217;re not that familiar with matrices you can use those. Effectively this filter allows you to modify every pixel of an image.</p>
<p>Here are some basics on matrices. If you define a matrix like this:</p>
<pre class="brush: xml; title: ; notranslate">
1   1   1   0.5   1
0.5 0.2 1   0.5   0.1
1   1   1   1     1
0.1 0.4 0.7 0.5   1
</pre>
<p>and the incoming colour is RGBA(75,22,48,0.5) then the outgoing colour will be RGBA(R, G, B, A) where R, G, B, A are defined below:</p>
<pre class="brush: xml; title: ; notranslate">
R = 1*75 + 1*22 + 1*48 + 0.5*0.5 + 1
G = 0.5*75 + 0.2*22 + 1*48 + 0.5*0.3 + 0.1
B = 1*75 + 1*22 + 1*48 + 1*0.5 + 1
A = 0.1*75 + 0.4*22 + 0.7*48 + 1*0.5 + 1
</pre>
<p>The fifth column does not refer to a specific channel, rather it is a constant offset. Defining that matrix with <code>feColorMatrix</code> would look a bit like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;colormatrix&quot;&gt;
    &lt;feColorMatrix type=&quot;matrix&quot; in=&quot;SourceGraphic&quot; values=&quot;1   1   1   0.5   1
                                                            0.5 0.2 1   0.3   0.1
                                                            1   1   1   1     1
                                                            0.1 0.4 0.7 1     1&quot;/&gt;
&lt;/filter&gt;
</pre>
<p>You don&#8217;t have to set a matrix though, and <code>feColorMatrix</code> provides different keywords which you can use instead of &#8216;matrix&#8217; in the type attribute. For example, you can set type to saturate, hueRotate or luminanceToAlpha and not even define a matrix, but rather a single value. For saturate its a number, for hueRotate is a degree (since we&#8217;re rotating) and for luminanceToAlpha there is no value since its predefined.</p>
<h3>feComponentTransfer</h3>
<p>Effectively allows you to &#8216;remap&#8217; a component (component meaning R, G, B or A channel). There are a few types and with each comes a specific way of altering the components.</p>
<ul>
<li>identity &#8211; default setting, no change</li>
<li>table &#8211; allows you to provide a list of numbers and a few calculations which alter the component channel</li>
<li>discrete &#8211; similar to table, in that we use a list of numbers. The calculation is quite complicated so I wont include it here</li>
<li>linear &#8211; uses equation new component = slope*C + intercept to gain new component. Uses slope and intercept attributes </li>
<li>gamma &#8211; uses equation new component = amplitude*C^exponent + offset to gain new component. Uses amplitude, exponent and offset attributes.</li>
</ul>
<p>We use the tags <code>feFuncR</code> for the R channel, <code>feFuncG</code> for the G channel, and so on.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;Identity&quot;&gt;
    &lt;feComponentTransfer&gt;
        &lt;feFuncR type=&quot;identity&quot;/&gt;
        &lt;feFuncG type=&quot;identity&quot;/&gt;
    &lt;/feComponentTransfer&gt;
&lt;/filter&gt;
&lt;filter id=&quot;Table&quot;&gt;
    &lt;feComponentTransfer&gt;
        &lt;feFuncR type=&quot;table&quot; tableValues=&quot;1 1 0 1&quot;/&gt;
        &lt;feFuncG type=&quot;table&quot; tableValues=&quot;1 0 0 1&quot;/&gt;
        &lt;feFuncB type=&quot;table&quot; tableValues=&quot;0 0 1 0&quot;/&gt;
    &lt;/feComponentTransfer&gt;
&lt;/filter&gt;
&lt;filter id=&quot;Linear&quot;&gt;
    &lt;feComponentTransfer&gt;
        &lt;feFuncR type=&quot;linear&quot; slope=&quot;.2&quot; intercept=&quot;.1&quot;/&gt;
        &lt;feFuncG type=&quot;linear&quot; slope=&quot;.45&quot; intercept=&quot;0&quot;/&gt;
        &lt;feFuncB type=&quot;linear&quot; slope=&quot;.9&quot; intercept=&quot;.23&quot;/&gt;
    &lt;/feComponentTransfer&gt;
&lt;/filter&gt;
&lt;filter id=&quot;Gamma&quot;&gt;
    &lt;feComponentTransfer&gt;
        &lt;feFuncR type=&quot;gamma&quot; amplitude=&quot;3&quot; exponent=&quot;5&quot; offset=&quot;0&quot;/&gt;
        &lt;feFuncG type=&quot;gamma&quot; amplitude=&quot;4&quot; exponent=&quot;4&quot; offset=&quot;2&quot;/&gt;
        &lt;feFuncB type=&quot;gamma&quot; amplitude=&quot;5&quot; exponent=&quot;3&quot; offset=&quot;0&quot;/&gt;
    &lt;/feComponentTransfer&gt;
&lt;/filter&gt;
</pre>
<h3>feComposite</h3>
<p>Creates a composite of two images using the porter duff compositing operations. Since we&#8217;re compositing we use two inputs. There are a few attributes that you might want to know:</p>
<ul>
<li>operator &#8211; can be set to over, in, out, atop, xor or arithmetic. </li>
<li>k1, k2, k3 and k4 &#8211; if set to arithmetic, you can use these attributes to determine numbers that change the effect. The calculation is done like so: result = k1*i1*i2 + k2*i1 + k3*i2 + k4, where i1 and i2 are the pixel data from input 1 and 2 respectively</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;composite&quot;&gt;
    &lt;feImage xlink:href=&quot;image.jpg&quot; result=&quot;myimage&quot; /&gt;
    &lt;feComposite in=&quot;SourceGraphic&quot; in2=&quot;myimage&quot; operator=&quot;arithmetic&quot; k1=&quot;.5&quot; k2=&quot;.5&quot; k3=&quot;.5&quot; k4=&quot;.5&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feConvolveMatrix</h3>
<p>A convolution combines pixels with neighbouring pixels to produce an output. <code>feConvolveMatrix</code> combines this effect with a matrix to set how the neighbouring pixels combine. There are a few attributes:</p>
<ul>
<li>order &#8211; the number of cells in the matrix. i.e. if it&#8217;s set to 3 each row will be 3 numbers long. If two numbers are set then the first will represent x and the second, y.</li>
<li>targetX &#8211; Determines the positioning in X of the convolution matrix relative to a given target pixel in the input image. The leftmost column of the matrix is column number zero.  </li>
<li>targetY &#8211; Determines the positioning in Y of the convolution matrix relative to a given target pixel in the input image. The topmost row of the matrix is row number zero. </li>
<li>edgeMode &#8211; can be <strong>duplicate</strong>, <strong>wrap</strong> or <strong>none</strong>. Determines how the pixel colours should be handled at the edge of images. For example, if set to duplicate the pixels at the edge of the image will be duplicated for as long as necessary. If set to wrap, then it&#8217;ll take the colours from the other side of the image. </li>
<li>kernelMatrix &#8211; The numbers that make up the matrix</li>
<li>kernelUnitLength &#8211; Indicates the distance between rows and columns. If two numbers are set then the first represents the columns and the second the rows. This is based off the units for the filter, i.e. the &#8216;primitiveUnits&#8217;, a setting which can be set to userSpaceOnUse or objectBoundingBox, which we covered before in gradients.</li>
<li>divisor &#8211; after applying the matrix to an image the output is divided by the divisor number if set.</li>
<li>bias &#8211; after applying the matrix and dividing it by the divisor, the bias is added to the number.</li>
<li>preserveAlpha &#8211; if transparency should be preserved or not.</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;convolvematrix&quot;&gt;
    &lt;feConvolveMatrix in=&quot;SourceGraphic&quot; order=&quot;3 3&quot; edgeMode=&quot;duplicate&quot; targetX=&quot;0&quot; targetY=&quot;0&quot; kernelMatrix=&quot;1 5 3 2 1 5 7 2 1&quot; preserveAlpha=&quot;false&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feDisplacementMap</h3>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/02/gradient.jpg" alt="" /><br />
    <span>A radial gradient applied to a displacement map (code below)</span>
</div>
<p>This filter uses the positions of one input to change the positions of another input, i.e. it alters one image using data from another image. For this reason it uses two inputs, a scale and you can set specifically which channel you want to filter (R, G, B or A), and specifically along which axis you want to select that channel.</p>
<pre class="brush: xml; title: ; notranslate">
  &lt;defs&gt;
	&lt;filter id=&quot;displace&quot;&gt;
	    &lt;feTurbulence  baseFrequency=&quot;.04&quot; numOctaves=&quot;2&quot; result=&quot;myturbulence&quot; /&gt;
	    &lt;feDisplacementMap in=&quot;SourceGraphic&quot; in2=&quot;myturbulence&quot; scale=&quot;20&quot; /&gt;
	&lt;/filter&gt;
	&lt;radialGradient id=&quot;gradient&quot; cx=&quot;250&quot; cy=&quot;90&quot; r=&quot;150&quot; gradientUnits=&quot;userSpaceOnUse&quot;&gt;
		&lt;stop offset=&quot;25%&quot; stop-color=&quot;green&quot;/&gt;
		&lt;stop offset=&quot;50%&quot; stop-color=&quot;blue&quot;/&gt;
		&lt;stop offset=&quot;75%&quot; stop-color=&quot;red&quot;/&gt;
	&lt;/radialGradient&gt;
  &lt;/defs&gt;
  
  &lt;rect fill=&quot;url(#gradient)&quot; x=&quot;30&quot; y=&quot;30&quot; width=&quot;300&quot; height=&quot;300&quot; filter=&quot;url(#displace)&quot; /&gt;
  
</pre>
<p>The above uses a turbulence filter (see feTurbulence for more info) as a source for a displacement map and then displaces the element based off data for that map. We applied a gradient to the rectangle which is then mapped to the displacement map.</p>
<h3>feFlood</h3>
<p>Effectively creates a rectangular area which is filled with a colour of your choosing. This can be used to create a solid colour and then used in other filters. The flood-colour is the colour, and the flood-opacity is the opacity (in case you didn&#8217;t get it!)</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;flood&quot;&gt;
    &lt;feFlood flood-color=&quot;green&quot; flood-opacity=&quot;0.5&quot;/&gt;
&lt;/filter&gt;

&lt;h3&gt;feGaussianBlur&lt;/h3&gt;
Just a simple blur. Not that difficult to accomplish. The &lt;code&gt;stdDeviation&lt;/code&gt; property is the amount of blur you wish to add. If you give two numbers the first will apply along the x axis and the second along the y axis. Sometimes this filter is used to create a sort of 'drop down shadow' effect.
1
&lt;filter id=&quot;blur&quot;&gt;
    &lt;feGassianBlur in=&quot;SourceGraphic&quot; stdDeviation=&quot;4&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feImage</h3>
<p>An image that you wish to use as part of the filtering process. Especially useful when wanting to blend two images with SVG using <code>feBlend</code>, although it can be used in a bunch of circumstances. The syntax is pretty simple, and the image is usually linked to another image via the result attribute.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;image&quot;&gt;
   &lt;feImage xlink:href=&quot;image.jpg&quot; result=&quot;myimage&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feMerge</h3>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/02/image.jpg" width="200" height="200" alt="" /><br />
    <span>A checkerboard image merged with a turbulence filter</span>
</div>
<p>Allows you to take multiple outputs and merge them. To do that we take our outputs via the result attirbute and merge them like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;merge&quot;&gt; 
    &lt;feTurbulence  baseFrequency=&quot;.04&quot; numOctaves=&quot;2&quot; result=&quot;myturbulence&quot; /&gt;
    &lt;feImage xlink:href=&quot;myimage.jpg&quot; width=&quot;50&quot; height=&quot;50&quot; result=&quot;myimage&quot; /&gt;
    &lt;!-- Merge them --&gt;
    &lt;feMerge&gt;
        &lt;feMergeNode in=&quot;myimage&quot;/&gt;
        &lt;feMergeNode in=&quot;myturbulence&quot;/&gt;
    &lt;/feMerge&gt;
&lt;/filter&gt;
</pre>
<h3>feMorphology</h3>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/02/text.jpg" alt="" />
</div>
<p>Thickens or thins shapes and artwork. It has an attribute called operator which can be set to erode (to make thinner) or dilate (to make fatter). Then we set a radius which is the amount we wish to erode or thicken the element by:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;thicker&quot;&gt;
    &lt;feMorphology operator=&quot;dilate&quot; radius=&quot;10&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feOffset</h3>
<p>Offsets the element we are applying the filter to. Effectively moves it a certain distance in the x and y directions.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;move&quot;&gt;
    &lt;feOffset in=&quot;sourceGraphic&quot; dx=&quot;20&quot; dy=&quot;40&quot; /&gt;
&lt;/filter&gt;
</pre>
<h3>feTile</h3>
<p><code>feTile</code> provides a way to take input of an image and tile it across an object. The syntax can be quite simple, all you have to do is define an image using feImage and then call the feTile tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;pattern&quot;&gt;
    &lt;feImage width=&quot;100&quot; height=&quot;100&quot; result=&quot;image1&quot; xlink:href=&quot;image.jpg&quot;/&gt;
    &lt;feTile /&gt;
&lt;/filter&gt;
</pre>
<h3>feTurbulence</h3>
<p>The <code>feTurbulence</code> filter creates a weird map of turbulence using a few attributes. This distorted map can then be used and applied to other filters to reach a desired effect. Here&#8217;s a list of all the attributes for <code>feTurbulence</code>: </p>
<ul>
<li>baseFrequency &#8211; effectively the amount of noise. It is a number. If two numbers are defined they represent the nose along the x and y axis respectively.</li>
<li>numOctaves &#8211; Affects how the noise looks </li>
<li>seed &#8211; The starting number for the random number generator</li>
<li>stitchTiles &#8211; can be set to <code>stitch</code> or <code>noStitch</code>. If set to no stitch no effort will be made to link tiles together, whereas if it&#8217;s set to stitch the filter will make it contain an even number of &#8216;noise&#8217; elements to improve linkage.</li>
<li>type &#8211; can be <code>fractalNoise</code> or <code>turbulence</code>. The fractalNoise filter makes the filter just produce noise, whereas turbulence creates a cool turbulence effect.</li>
</ul>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;turbulence&quot;&gt;
    &lt;feTurbulence  baseFrequency=&quot;.04&quot; numOctaves=&quot;2&quot; result=&quot;myturbulence&quot; /&gt;
&lt;/filter&gt;
</pre>
<h2>Lighting Effects</h2>
<p>It is possible to even add lighting effects with SVG&#8217;s magnificent filter system. There are two types of lighting, <code>feDiffuseLighting</code and <code>feSpecularLighting</code>. Specular lighting uses <a href="http://en.wikipedia.org/wiki/Phong_reflection_model">this model</a>. Diffuse lighting can also be seen on that page in the image under description. There are also 3 main tags which determine lighting that go inside these two tags:</p>
<ul>
<li><code>feDistantLight</code> &#8211; has the attributes <strong>azimuth</strong>, which is the angle between the x and y axis, and <strong>elevation</strong>, which is how far up the light source is positioned</li>
<li><code>fePointLight</code> &#8211; Sets a light source at a specific coordinate using x, y, and z attributes</li>
<li><code>feSpotLight</code> &#8211; Sets a spot light using x, y and z coordinates. Then it sets where the spot light is pointing at with pointsAtX, pointsAtY and pointsAtZ. Then sets a limiting factor in degrees to where the light cannot point using limitingConeAngle </li>
</ul>
<h3>Example of 3 light sources</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- A distant light --&gt;
&lt;feDistantLight azimuth=&quot;40&quot; elevation=&quot;20&quot;/&gt;

&lt;!-- A point light --&gt;
&lt;fePointLight x=&quot;200&quot; y=&quot;30&quot; z=&quot;10&quot; /&gt;

&lt;!-- A spot light --&gt;
&lt;feSpotLight x=&quot;70&quot; y=&quot;100&quot; z=&quot;20&quot; limitingConeAngle=&quot;40&quot; pointsAtX=&quot;250&quot; pointsAtY=&quot;40&quot; pointsAtZ=&quot;0&quot;/&gt;
</pre>
<p>Basically you pick a light source and place it in a light type, either diffuse or specular. Again, these have numerous settings. For both diffuse lighting and specular you can set a lighting colour, i.e. the colour of the light you wish to use.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;filter id=&quot;diffuse&quot;&gt;
    &lt;feDiffuseLighting in=&quot;SourceGraphic&quot; result=&quot;diffuselighting&quot; lighting-color=&quot;white&quot;&gt;
        &lt;fePointLight x=&quot;200&quot; y=&quot;30&quot; z=&quot;10&quot; /&gt;
    &lt;/feDiffuseLighting&gt;
&lt;/filter&gt;

&lt;filter id=&quot;specular&quot;&gt;
    &lt;feDiffuseLighting in=&quot;SourceGraphic&quot; result=&quot;specularlighting&quot; lighting-color=&quot;white&quot;&gt;
        &lt;fePointLight x=&quot;200&quot; y=&quot;30&quot; z=&quot;10&quot; /&gt;
    &lt;/feSpecularLighting&gt;
&lt;/filter&gt;
</pre>
<h2>Filters to Create Drop Shadows</h2>
<p>There is no &#8216;drop shadow&#8217; tag in SVG, so we sort of have to improvise. Basically, we take the element we want to give a drop shadow and add a filter which takes the element, offsets it, blurs it and removes colour, and then we use a colour matrix to lower the opacity. Sound pretty complicated? Well for a drop shadow, it is pretty complicated. But it&#8217;s doable. Here is the code, which should give this green square a drop shadow. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
	&lt;filter width=&quot;200%&quot; height=&quot;200%&quot; id=&quot;dropshadow&quot;&gt;
	    &lt;feOffset result=&quot;offset&quot; in=&quot;SourceAlpha&quot; dx=&quot;20&quot; dy=&quot;20&quot; /&gt;
	    &lt;feGaussianBlur result=&quot;gaus&quot; in=&quot;offset&quot; stdDeviation=&quot;10&quot; /&gt;
	    &lt;feColorMatrix in=&quot;gaus&quot; result=&quot;color&quot; type=&quot;matrix&quot;
	          values=&quot;0 0 0 0   0
	                  0 0 0 0   0 
	                  0 0 0 0   0 
	                  0 0 0 .3  0 &quot;/&gt;
	    &lt;feBlend in=&quot;SourceGraphic&quot; in2=&quot;color&quot; mode=&quot;normal&quot; /&gt;
	&lt;/filter&gt;
&lt;/defs&gt;

&lt;rect fill=&quot;green&quot; x=&quot;30&quot; y=&quot;30&quot; width=&quot;200&quot; height=&quot;200&quot; filter=&quot;url(#dropshadow)&quot; /&gt;

</pre>
<h2>Summary</h2>
<p>We&#8217;ve covered quite a bit in this part. Next time we&#8217;ll cover things like animations, interactions and transforms, as well as a few other cool features, so stay tuned! The best way to learn is to experiment, so open up a new SVG document and try out some of the things shown here. Don&#8217;t forget to read part 1 if you missed it, and have a good day!</p>
<p><a href="http://www.inserthtml.com/2013/01/svg-guide-part-1/">Part 1</a> &bull; <a href="#">Part 2</a></p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3936&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=tR3Yh472tgE:LFVChwFLTn8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=tR3Yh472tgE:LFVChwFLTn8:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=tR3Yh472tgE:LFVChwFLTn8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=tR3Yh472tgE:LFVChwFLTn8:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=tR3Yh472tgE:LFVChwFLTn8:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/tR3Yh472tgE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/02/svg-guide-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/02/svg-guide-part-2/</feedburner:origLink></item>
		<item>
		<title>The Future of CSS3: Looking at Future Techniques Today</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/WeGboHddCnA/</link>
		<comments>http://www.inserthtml.com/2013/01/future-css3/#comments</comments>
		<pubDate>Tue, 29 Jan 2013 18:00:31 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[blending]]></category>
		<category><![CDATA[exclusions]]></category>
		<category><![CDATA[masks]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3650</guid>
		<description><![CDATA[It&#8217;s a brand new year and with that comes hope for better web standards. Just last November a new specification was published: The CSS Mask Specification. This is an official specification on something that webkit browsers could do for a long time (mask images), which means it&#8217;s going to be implemented in other browsers now too. What else will CSS&#8230;]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s a brand new year and with that comes hope for better web standards. Just last November a new specification was published: The CSS Mask Specification. This is an official specification on something that webkit browsers could do for a long time (mask images), which means it&#8217;s going to be implemented in other browsers now too. What else will CSS bring to the table in the coming year?</p>
<h1>CSS Masks</h1>
<p>Masks have been around for a long time, and were initially implemented by webkit browsers as a pretty neat feature, albeit one we could never really use because it wasn&#8217;t a standard. Time passed, and now we have a real W3C specification on CSS masks, which will most likely be implemented by major browsers in the coming months. </p>
<p>So what exactly is a mask? To put it simply, in a mask we will have an image or element, and then a image consisting of a black or white shape with a transparent background. <strong>If we apply the mask to our image or element, the image or element will be &#8216;mapped&#8217; to the mask. This means that the black or white area will be replaced by the image or element we are masking.</strong> For example:</p>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/masks1.png" alt="" width="600" height="222" /><br />
<span>In the mask, the white circles are actually transparent</span>
</div>
<h2>Mask Implementation</h2>
<p>Masks can be used today, but unfortunately not to their full potential. Currently Webkit is the only browser supporting masks. Webkit currently only supports alpha masks, which means if you have a mask, it doesn&#8217;t matter what colour the shape is, the content will be clipped to it. </p>
<p>The other kind of mask is luminance (not supported yet). <strong>Luminance masks are black and white, where the white areas will show the image, and the black will not.</strong> Grey areas will show the image slightly depending on how white they are (effectively, the darker the grey area the lower the opacity of whatever you&#8217;re masking).</p>
<h2>Webkit Implementation</h2>
<p>Masks are easy to use in webkit, in fact you can just use the <code>mask</code> css tag:</p>
<pre class="brush: css; title: ; notranslate">
.element {
     -webkit-mask: url('mask.png');
}
</pre>
<p>Lets try to create a working example though. Here is our mask image (We&#8217;re using alpha, so the best thing to do is a black shape on a transparent background):</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/mask-image.png" alt="" /><br />
    <span>Our Mask Image</span>
</div>
<p>Now lets say we have an image (HTML elements work too!). For this simple example we&#8217;ll use an image. Here is the image I&#8217;m going to use:</p>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/image.jpeg" width="500" height="334" alt="" /><br />
   <span>Created by <a href="http://www.flickr.com/photos/mark-braggins/">Mark Braggins</a>
</div>
<p>With a little HTML and CSS:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;element&quot;&gt;
    &lt;img src=&quot;image.jpeg&quot; alt=&quot;&quot; /&gt;
&lt;/div&gt;
</pre>
<pre class="brush: css; title: ; notranslate">
&lt;style type=&quot;text/css&quot;&gt;
.element {
   width: 500px;
   overflow: hidden;
}

.element img {
    -webkit-mask: url(mask-image.png);
}
&lt;/style&gt;
</pre>
<p>We end up with this in webkit browsers:</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/final-mask.jpg" alt="" />
</div>
<p>It&#8217;s also possible to use properties that you would expect on background tags with masks. For example, you can set the position:</p>
<pre class="brush: css; title: ; notranslate">



.element img {
     /* Mask URL, Mask position, repeat mask?, how far should the mask mask? (content-box, padding-box or border-box?) */ 
    -webkit-mask: url(mask-image.png) 30% 30% repeat-x border-box;
    
    /* .. is the same as.. */
    -webkit-mask-image: url(mask-image.png);
    -webkit-mask-position: 30% 30%;
    -webkit-mask-repeat: repeat-x;
    -webkit-mask-box-clip: border-box;
    
    /* You can also set size! */
    -webkit-mask-size: 30% 30%;
}
</pre>
<h1>CSS Exclusions</h1>
<p>CSS Exclusions have very little support but they&#8217;re really going to improve how we design content for websites. Using just one simple property you can easily change the entire landscape of a document, almost as if editing it in a WYSIWYG editor. So how do CSS exclusions work? The most interesting property is <em>wrap-flow</em>.</p>
<h2>Wrap-flow</h2>
<p>Wrap flow allows you to determine how elements will affect other elements when they are placed on top of other elements. Normally when you move an element on top of another element (via position relative, etc) the blocks will overlap. Using <em>wrap-flow</em> however, the other elements will be forced to adapt to fit around the element placed on top.</p>
<p>Wrap-flow can have quite a few settings. It can be set to auto, start, end, both, minimum, maximum or clear.</p>
<ul>
<li><strong>auto</strong>: normal behaviour, none of the element is adjusted</li>
<li><strong>start</strong>: everything after the element is removed</li>
<li><strong>end</strong>: everything before the element is removed</li>
<li><strong>both</strong>: only content below the object is removed</li>
<li>minimum: the side with the most content is removed</li>
<li><strong>maximum</strong>: the side with the least content is removed</li>
<li><strong>clear</strong>: all content is removed from the height of the object</li>
</ul>
<p>That probably makes no sense to you, so here are some diagrams to help!</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/exclusion.gif" width="600" height="400" alt="" />
</div>
<p>The content will usually be text, so the text will be wrapped around the overlapping pieces. Any movement of the overlapping pieces will change the shape of the content to fit with them.</p>
<h1>Composition and Blending</h1>
<p>Yeah that&#8217;s right, blending modes in CSS has become an official specification. That means you&#8217;ll be able to do things like color burn with just CSS! As you&#8217;d imagine, support is non existant due to it being a brand new specification, but it is certainly something to get excited about. The specification is still pretty new so there will be changes before it hits browsers, but effectively you will have two images, one placed over the other via absolute positioning. It might look a little like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;blend&quot;&gt;
   &lt;img src=&quot;duck.gif&quot; alt=&quot;Duck&quot; class=&quot;duck&quot; width=&quot;500&quot; height=&quot;500&quot; style=&quot;position: absolute; top: 0; left: 0&quot; /&gt;
   &lt;img src=&quot;penguin.gif&quot; alt=&quot;Penguin&quot; class=&quot;penguin&quot; width=&quot;500&quot; height=&quot;500&quot; style=&quot;position: absolute; top: 0; left: 0&quot; /&gt;
&lt;/div&gt;
</pre>
<p>Your CSS might then look a little like this:</p>
<pre class="brush: css; title: ; notranslate">
.blend {
     position: relative;
}
.blend .duck {    
     mix-blend-mode: overlay;
}
</pre>
<p>Such a combination might look a little like this:</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/duckguin.jpg" alt="" /><br />
    <span>The duck looks a little ominous, but it gives you an idea of what it would look like</span>
</div>
<p><strong>It is possible to try out CSS blending modes if you&#8217;re interested</strong>. First you need to download <a href="https://github.com/downloads/adobe/webkit/PrototypeEnhancementsForChromiumMac-may2012-f2f.zip">Adobe&#8217;s experimental webkit browser</a>. Then <a href="http://adobe.github.com/web-platform/demos/compositing/image-blend-modes.html">visit this page</a> with the experimental browser to see them all in action! That&#8217;s about all for today, but stay tuned for more CSS updates and guides.</p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3650&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=WeGboHddCnA:bsVsUQVqvcE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WeGboHddCnA:bsVsUQVqvcE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WeGboHddCnA:bsVsUQVqvcE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=WeGboHddCnA:bsVsUQVqvcE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WeGboHddCnA:bsVsUQVqvcE:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/WeGboHddCnA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/01/future-css3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/01/future-css3/</feedburner:origLink></item>
		<item>
		<title>What is SVG? [Guide to SVG Part 1]</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/u-Fz0cXNJ5E/</link>
		<comments>http://www.inserthtml.com/2013/01/svg-guide-part-1/#comments</comments>
		<pubDate>Tue, 22 Jan 2013 16:47:14 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[svg]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[guide]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3551</guid>
		<description><![CDATA[SVG (Scalable Vector Graphics) is a very useful tool for drawing shapes and figures with simple code. It is probably one of the most useful tools that web designers are hesitant to use, although once you understand it, you&#8217;ll wonder how you lived without it! In this series we&#8217;ll be going through the basics of SVG, including how to use&#8230;]]></description>
				<content:encoded><![CDATA[<p>SVG (Scalable Vector Graphics) is a very useful tool for drawing shapes and figures with simple code. It is probably one of the most useful tools that web designers are hesitant to use, although once you understand it, you&#8217;ll wonder how you lived without it! In this series we&#8217;ll be going through the basics of SVG, including how to use it and what it can do for you. </p>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2012/12/svg.gif" alt="SVG Banner Image" width="600" height="300" />
</div>
<div class="alert">
    This article is part of a series! If you want to stay up to date don&#8217;t forget to follow or subscribe!
</div>
<p><a href="#">Part 1</a> &bull; <a href="http://www.inserthtml.com/2013/02/svg-guide-part-2/">Part 2</a></p>
<h2>What we will cover in this part</h2>
<ul>
<li>Basic Structure of SVG</li>
<li>Tools you can use to make SVG documents more easily</li>
<li>Basic shapes and drawings with SVG</li>
<li>Embedding SVG files</li>
<li>How to use paths</li>
<li>More advanced structural elements</li>
</ul>
<h2>What kind of language is SVG?</h2>
<p><strong>SVG is XML based, which means we use tags similar to the kind we use in HTML.</strong> In fact, if you know HTML, SVG should be a breeze. SVG is pretty easy to implement in the core tenants of web design (CSS, HTML and Javascript) and with the rise of an &#8216;imageless&#8217; web, SVG is going to be a fundamental component to cross device compatibility. </p>
<h2>How do we begin?</h2>
<p>Starting a new SVG document is really easy! <strong>First make a .svg file (for example, file.svg) and open it in your text editor of choice.</strong> Like any XML based document, we will begin with some semantics. That just means we have a few lines telling the browser exactly what we are creating. <strong>So your run of the mill (or how you will start most of your SVG documents) SVG document might look a little like this:</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; standalone=&quot;no&quot;?&gt;
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;

&lt;/svg&gt;
</pre>
<p>An SVG document has a width and a height, something you might not be accustomed to in HTML. Apart from that most things shouldn&#8217;t be that different. <strong>All the SVG code you&#8217;re going to write is going to go inside the <code>&lt;svg></code> tags. </strong></p>
<h2>Tools of the trade</h2>
<div class="image-right">
<img src="http://www.inserthtml.com/wp-content/uploads/2012/12/inkscape.jpg" alt="Inkscape" width="225" height="188" /><br />
<span><a href="http://inkscape.org/">INKSCAPE</a></span>
</div>
<p>Before we begin it&#8217;s important to note that although SVG does involve sometimes coding things by hand, there are programs that make it a lot easier. One of the most popular is called <a href="http://inkscape.org/"><strong>Inkscape</strong></a>, which allows you to create objects and export them as SVG files. If you want to continue with SVG I sincerely suggest downloading Inkscape (it&#8217;s free!) and using it in conjunction with hard coding SVG.</p>
<p><strong>On top of that, <a href="http://www.adobe.com/products/illustrator.html">Adobe Illustrator</a> also has SVG functionality and you can save your files as SVG files.</strong> If you have Illustrator this would probably be the best choice, however Inkscape provides a free alternative.</p>
<h2>Basic Structure of SVG</h2>
<p>SVG is all about semantics (that&#8217;s the order and grouping of information, in case you didn&#8217;t know). For that reason it&#8217;s pretty customary to start every SVG file with a title and description. Before we do that though, you should know about the main grouping tag in SVG, <code>&lt;g></code>. The <code>&lt;g></code> groups together similar elements or objects that are related in SVG. It&#8217;s kind of like <code>&lt;div></code>, although with a bit more of an SVG slant. </p>
<p>The title and description tags are <code>&lt;title></code> and <code>&lt;desc></code> respectively. Since they are related, we will group them together with a &lt;g> tag. Therefore, in effect, every SVG document you write should look a bit like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; standalone=&quot;no&quot;?&gt;
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 100 100&quot;&gt;
   &lt;g&gt;
      &lt;title&gt;The Title for your SVG File&lt;/title&gt;
      &lt;desc&gt;The description goes here! E.g. 'a red and black cube'&lt;/desc&gt;
   &lt;/g&gt;
&lt;/svg&gt;
</pre>
<h3>Understanding viewBoxes</h3>
<p>You might understand the quite strange property viewBox above on the svg tag. To understand exactly what that is let me give you an example. Without the viewbox property, the SVG tag will still work. Suppose you try to define a coordinate (the main way we define shapes in SVG) on the SVG document. So lets say we want a circle at (50, 50). Without the viewBox that point will be 50 pixels in and 50 pixels down. </p>
<p>However, since we have a viewBox, we change the grid system completely. Our view box is <strong>0 0 100 100</strong>. That means that the point at the very left hand edge and the very top of the SVG document is 0 and 0, and the point at the very bottom and very far right of the SVG document is 100 and 100. So (50, 50) with a viewBox of 0 0 100 100 is 50% across and 50% down, rather than 50 pixels. ViewBoxes can be anything, and have the following syntax:</p>
<pre class="brush: xml; title: ; notranslate">
viewBox=&quot;min-x min-y width height&quot;
</pre>
<p>You could have a viewBox of <strong>50 100 200 250</strong>. That means a coordinate of (50, 100) is in the very top left corner of the SVG document, and the very bottom right corner is (200, 250)!</p>
<h2>Embedding SVG in HTML and CSS</h2>
<p>SVG is easily embeddable into HTML documents, and therefore easily incorporated into your web designs. First off, SVG elements can be used as backgrounds in CSS:</p>
<pre class="brush: css; title: ; notranslate">
background: url('file.svg');
</pre>
<p>On top of that, SVG can be embedded directly into an HTML document with the embed property. This is supported in HTML5 and all major browsers, so is safe enough to use:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;embed src=&quot;file.svg&quot; type=&quot;image/svg+xml&quot; /&gt;
</pre>
<p>It&#8217;s also possible to directly put SVG in an HTML document with the SVG tag like so:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;body&gt;

&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; version=&quot;1.1&quot;&gt;
  &lt;!-- SVG CODE GOES HERE --&gt;
&lt;/svg&gt;

&lt;/body&gt;
</pre>
<h2>Basic Shapes</h2>
<div class="image">
<img src="http://www.inserthtml.com/wp-content/uploads/2012/12/shapes.gif" alt="Basic Shapes" width="600" height="400" />
</div>
<p>Drawing shapes in SVG uses co-ordinates inside the SVG document to define things like radius, amongst others. Along with these basic shapes we&#8217;ll be looking at a few basic properties that allow us to style the various shapes. These are pretty self explanatory and applicable to all the other shapes.</p>
<h3>Rectangles</h3>
<pre class="brush: xml; title: ; notranslate">
&lt;rect x=&quot;20&quot; y=&quot;20&quot; width=&quot;100&quot; height=&quot;200&quot; fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; /&gt;
</pre>
<p>The above draws a rectangle whose top left point is at (20, 20) (that&#8217;s 20 pixels in from the left, and 20 pixels down from the top). It has a width of 100 and a height of 100. It is #f2ebdf in colour (the fill property defines the colour), and has a #e3d8c6 stroke around the edge that is 10 pixels in width.</p>
<h3>Circle</h3>
<p>Since circles are defined by their radius, we need to define radius property.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;circle cx=&quot;100&quot; cy=&quot;100&quot; r=&quot;100&quot; fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; /&gt;
</pre>
<p>Another easy to miss detail when defining a circle is we define the position of the center of the circle, so rather than just using <em>x</em> we use <em>cx</em>.</p>
<h3>Ellipses</h3>
<p>Quite similar to circles, only we define the radius for the x and y directions. For this, we use the <em>rx</em> and <em>ry</em> properties. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;ellipse cx=&quot;200&quot; cy=&quot;300&quot; rx=&quot;120&quot; ry=&quot;100&quot; fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; /&gt;
</pre>
<h3>Polygons</h3>
<p>Polygons are shapes with multiple points. To mark every point, we us a property called <em>points</em>, separating each point by a space. The final point will then be joined up to the first point creating a custom shape. For this reason, there is no need to define a width or height.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;polygon fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; points=&quot;30,60 120,50 180,20 20,10&quot; /&gt;
</pre>
<p>So the above polygon will go from (30, 60) to (120, 50) to (180, 20), etc, before returning back to (30, 30).</p>
<div class="alert">
    You can apply things like &#8216;stroke&#8217; to a &lt;g> element, and then all the elements in the &lt;g> element will inherit it!
</div>
<h2>Lines</h2>
<p>Lines aren&#8217;t shapes, but they follow a similar procedure and syntax to what we would expect from a shape element. There are two ways to draw lines, the first being a single line from one point to another and the second being a polyline which encompasses many points and can turn. </p>
<pre class="brush: xml; title: ; notranslate">
&lt;line x1=&quot;100&quot; y1=&quot;20&quot; x2=&quot;200&quot; y2=&quot;40&quot; stroke=&quot;black&quot; stroke-width=&quot;25&quot;  /&gt;
</pre>
<p>The above single line will go from (100, 20) to (200, 40). <strong>A polyline</strong> is pretty straight forward too. A syntax similar to the polygon is used:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;polyline fill=&quot;none&quot; stroke=&quot;black&quot; stroke-width=&quot;25&quot; points=&quot;10,20 40,55 100,120 50,20 &quot; /&gt;
</pre>
<p>Again, similar to polygons, each set of points in the points property defines a point which the line will go through.</p>
<h2>Paths</h2>
<p>Paths are a little more complicated than what we&#8217;ve been used to so far. Paths use letters to define their shape. This gives us a lot more flexibility when drawing shapes.</p>
<pre class="brush: xml; title: ; notranslate">
   &lt;path d=&quot;M 350,75 L 379,161 L 469,161 L 397,215 L 423,301 L 350,250 L 277,301 L 303,215 L 231,161 L 321,161 z&quot; fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; /&gt;
</pre>
<p>So what exactly does this mean? The <em>d</em> property is similar to the <em>points</em> property for polygons and polylines. When we say M in a path we want to move to that point without drawing a line. So M 350,75 means move to point (350, 75) without drawing a line. L means draw a line, so L 379,161 means move to (379, 161). The z at the very end means &#8216;the end&#8217;, and terminates the shape. <strong>Note that it is still possible to continue after z which starts a new path, so we could do this</strong>:</p>
<pre class="brush: xml; title: ; notranslate">
   &lt;path d=&quot;M 350,75 L 379,161 L 469,161 L 397,215 L 423,301 L 350,250 L 277,301 L 303,215 L 231,161 L 321,161 z M 100,100 L 200,200&quot; fill=&quot;#f2ebdf&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;1&quot; /&gt;
</pre>
<p>Below is a list of all the letters and everything they do. Try learning them!</p>
<table class="deftable" cellspacing="0">
<tr>
<td>Letter</td>
<td>Syntax</td>
<td>Purpose</td>
</tr>
<tr>
<td>M or m</td>
<td>M x,y (<em>Ex: M 20,400</em>)</td>
<td>Moves to a point on the SVG document without drawing a line</td>
</tr>
<tr>
<td>L or l</td>
<td>L x,y (<em>Ex: L 40,20</em>)</td>
<td>Draws a line from the previously defined point to the point defined after L</td>
</tr>
<tr>
<td>H or h</td>
<td>H x (<em>Ex: H 30</em>)</td>
<td>Draws a horizontal line from the previously defined point to the x coordinate defined after the H</td>
</tr>
<tr>
<td>V or v</td>
<td>V y (<em>Ex: H 30</em>)</td>
<td>Draws a vertical line from the previously defined point to the y coordinate defined after the V</td>
</tr>
<tr>
<td>C or c</td>
<td>C x1,y1 x2,y2 x,y (<em>Ex: C 50,40 100,40 100,100</em>)</td>
<td>Draws a cubic Bézier curve from the previously defined point to (x,y) using (x1,y1) and (x2,y2) as control points <strong>(See below for definition of control points)</strong></td>
</tr>
<tr>
<td>S or s</td>
<td>S x2,y2 x,y (<em>Ex: S 50,40 100,100</em>)</td>
<td>Draws a cubic Bézier curve from the previously defined point to (x,y) using (x2,y2) as a control point and assuming that (x1,y1) is a mirror of (x2,y2) <strong>on the previous command</strong>. If there was no previous command (x2,y2) is assumed to be the same as (x,y) <strong>(See below for definition of control points)</strong></td>
</tr>
<tr>
<td>Q or q</td>
<td>Q x1,y1 x,y (<em>Ex: S 100,40 30,10</em>)</td>
<td>Draws a quadratic Bézier curve from the previously defined point to (x,y) using (x1,y1) as a control point <strong>(See below for definition of control points)</strong></td>
</tr>
<tr>
<td>T or t</td>
<td>T x,y (<em>Ex: T 100,40</em>)</td>
<td>Draws a quadratic Bézier curve from the previously defined point to (x,y) assuming the control point is the mirror of the control point in the previous command. If you didn&#8217;t have a control point in the previous command the control point is assumed to be the same as (x,y) <strong>(See below for definition of control points)</strong></td>
</tr>
<tr>
<td>A or a</td>
<td>A rx,ry x-axis-rotation large-arc?,sweep? x,y (<em>Ex: A 100,40 30 0,0 20,20</em>)</td>
<td>Draws an arc from the previously defined point to (x,y) based on the radii (rx,ry) and the rotation of the curve (x-axis-rotation). Two boolean functions can be set to further define the curve (large-arc,sweep) which are either set to 1 or 0. <strong>(See below for more information on large-arc and sweep)</strong></td>
</tr>
</table>
<h3>Hey! What&#8217;s the difference between uppercase and lowercase?</h3>
<p>You may have noticed that both uppercase and lowercase letters can be used. You&#8217;d be right in thinking there is a difference. When you use an uppercase letter the point is defined from the top left of document. So the point (100, 100) is 100 pixels across and 100 pixels down from the top left of the document. </p>
<p><strong>If you use a lowercase letter, however</strong>, the point is defined <strong>relative to the last point</strong>. So suppose you have <em>M 100,100 l 20,20</em>. You move to point (100,100) and <strong>then draw a line to (120, 120)</strong>. Effectively, the last point becomes your zero point.</p>
<h3>Control Points?</h3>
<p>That might sound confusing, but it&#8217;s just like when you use photoshop and the pen tool. Cubic and Quadratic Bézier curves are mathematical functions, and the control points help define that function. Consider the following path:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;path d=&quot;M 10,10 C 200,100 100,300 300,300 M 10,10 z&quot; fill=&quot;white&quot; stroke=&quot;#e3d8c6&quot; stroke-width=&quot;3&quot; /&gt;
</pre>
<p>The control points are at (200, 100) and (100, 300). The curve is drawn from (10, 10) to (300, 300). Below is an annotated diagram of that curve.</p>
<div class="image">
<img src="http://www.inserthtml.com/wp-content/uploads/2012/12/controlpoints.gif" alt="Control Point Diagram" width="374" height="326" />
</div>
<p>Quadratic Bézier curves differ only in the fact that they have a single control point, large arc and sweep. You can set these to either 1 or 0, and they give us quite odd results.</p>
<h3>Arcs</h3>
<p>Arcs are a little more tricky in that they have these odd boolean settings large arc and sweep. Below is a diagram showing exactly how they work. They can be set to either 1 or 0. </p>
<div class="image">
<img src="http://www.inserthtml.com/wp-content/uploads/2012/12/arcs.gif" alt="Arc Diagram" width="639" height="383" />
</div>
<h2>More Advanced Structure</h2>
<p>Now that we understand the basic concepts behind drawing on a SVG document, lets look in a little bit more detail at the structure of an SVG document. There are many structural elements in SVG which can be used to help you when creating something.</p>
<h3>Definitions and Use</h3>
<p>We can define elements in SVG that we use a lot for easy use. This could be useful if you&#8217;re using the same gradient a lot, but we&#8217;ll get to that in part 2 of this series. For now we&#8217;ll look at how we can combine definitions with another element called use.</p>
<p>First off, defining something is pretty easy. If you want to define a reusable element, that element must go inside a tag called <code>&lt;defs></code>. You can have multiple definitions inside a single defs tag, but each must have a unique ID. For example, below I define 2 rectangles:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;defs&gt;
   &lt;rect id=&quot;definition1&quot; width=&quot;120&quot; height=&quot;50&quot; fill=&quot;red&quot; /&gt;
   &lt;rect id=&quot;definition2&quot; width=&quot;500&quot; height=&quot;20&quot; fill=&quot;blue&quot; /&gt;
&lt;/defs&gt;
</pre>
<p>But what exactly is the use of defining stuff? Well, definitions do not show up directly in your SVG document, but we can call upon these definitions and use them anywhere using the use tag. There are other ways to use definitions with different calling methods but we&#8217;ll get to that in the follow up parts to this guide.</p>
<p>So we can use a definition with the <code>&lt;use></code> tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;use x=&quot;30&quot; y=&quot;30&quot; xlink:href=&quot;#definition1&quot; /&gt;
</pre>
<p>This will call upon our definition which has the id definition1. The <em>xlink:href</em> property is just a way to link up with the definition of our choice. The xlink attribute is not actually a part of SVG and wont work, so to use this we need to change our SVG tag to tell the browser that we want to be able to use it. To do that, just change your SVG tag from something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;&gt;
</pre>
<p>to this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;svg width=&quot;500&quot; height=&quot;400&quot; version=&quot;1.1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
</pre>
<p>Since SVG is totally scalable we can define the use element with different widths and heights and the object in our definition will change size depending on that. For example we could easily define our rectangle has half the width and height in the use tag, and it would display that way.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;use x=&quot;30&quot; y=&quot;30&quot; width=&quot;60&quot; height=&quot;25&quot; xlink:href=&quot;#definition1&quot; /&gt;
</pre>
<p>So the use tag above will be replaced by the rectangle that we called. This has more apparent uses when creating complex shapes that are used a lot, which can then be resized at will.</p>
<h3>Symbols</h3>
<p>Speaking of <code>&lt;use></code>, we can also call upon a <code>&lt;symbol></code> tag to be called upon later in an SVG document. A symbol can be called within or outside the <code>&lt;defs></code> tag, and will not appear in the document until you call it with a use tag. </p>
<p><strong>The main difference between a symbol and definitions is that a symbol is a single object, and a symbol can have a custom viewBox.</strong> So you can redefine a viewBox specifically for a symbol. Otherwise, it&#8217;s much the same as a definition:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;symbol id=&quot;symbol1&quot;&gt;
   &lt;rect width=&quot;120&quot; height=&quot;50&quot; fill=&quot;red&quot; /&gt;
   &lt;rect width=&quot;500&quot; height=&quot;20&quot; fill=&quot;blue&quot; /&gt;
&lt;/defs&gt;
</pre>
<p>Which can then be called to be put into a document using the use tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;use x=&quot;30&quot; y=&quot;30&quot; xlink:href=&quot;#symbol1&quot; /&gt;
</pre>
<h3>Summary</h3>
<p>In this tutorial we have covered some of the core tenets of SVG, from basic structure to drawing shapes amongst other things. In part 2 we will look at styling in more depth as well as some other awesome things SVG can do. Don&#8217;t forget to subscribe or follow to make sure you don&#8217;t miss it!</p>
<p><a href="#">Part 1</a> &bull; <a href="http://www.inserthtml.com/2013/02/svg-guide-part-2/">Part 2</a></p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3551&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=u-Fz0cXNJ5E:gSGN72Lz9Ts:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=u-Fz0cXNJ5E:gSGN72Lz9Ts:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=u-Fz0cXNJ5E:gSGN72Lz9Ts:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=u-Fz0cXNJ5E:gSGN72Lz9Ts:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=u-Fz0cXNJ5E:gSGN72Lz9Ts:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/u-Fz0cXNJ5E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/01/svg-guide-part-1/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/01/svg-guide-part-1/</feedburner:origLink></item>
		<item>
		<title>“Infinite” Scroll to Load More Content Pagination with jQuery</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/1qN_hRzi8y8/</link>
		<comments>http://www.inserthtml.com/2013/01/scroll-pagination/#comments</comments>
		<pubDate>Tue, 15 Jan 2013 16:36:08 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[pagination]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3542</guid>
		<description><![CDATA[Pagination with numbers is, in many ways, counter intuitive and time consuming for the user. They have to stop, click on a number, wait for the page to load, and then continue their search. Some websites such as facebook have opted out of this notion of pagination for a system which loads content automatically as the user scrolls. In this&#8230;]]></description>
				<content:encoded><![CDATA[<p>Pagination with numbers is, in many ways, counter intuitive and time consuming for the user. They have to stop, click on a number, wait for the page to load, and then continue their search. Some websites such as facebook have opted out of this notion of pagination for a system which loads content automatically as the user scrolls. In this tutorial that is what we&#8217;re going to be making.</p>
<h2>How it works</h2>
<p>I&#8217;ve created a little plugin that allows us to accomplish our goal. Simply put the plugin checks if the user is at the bottom of the container you specify and loads more content accordingly. Then this data is sent to an ajax file which processes what posts to show.</p>
<pre class="brush: jscript; title: ; notranslate">
// Check the user is at the bottom of the element
if($(window).scrollTop() + $(window).height() &gt; $this.height() &amp;&amp; !busy) {
						
	// Now we are working, so busy is true
	busy = true;
						
	// Tell the user we're loading posts
	$this.find('.loading-bar').html('Loading Posts');
			
	// Run the function to fetch the data inside a delay
	// This is useful if you have content in a footer you
	// want the user to see.
	setTimeout(function() {
		// This is the Ajax function					
		getData();
							
	}, $settings.delay);
							
}	

</pre>
<p>The key line here is <code>if($(window).scrollTop() + $(window).height() > $this.height() ..</code>. This is basically saying, if the user scroll position is greater than the height of the element targeted, then more elements should be loaded.</p>
<h3>What is Ajax?</h3>
<div class="image">
<img src="http://www.inserthtml.com/wp-content/uploads/2012/12/example.gif" alt="AJAX Example" width="421" height="323" class="aligncenter size-full wp-image-3564" />
</div>
<p>Ajax is how we send data to files when an event happens in javascript. For example, when we scroll we want to send some data to another file to figure out what to do. That file is usually a PHP file which will <em>process</em> the data sent, and then you can do something like grab information from a database. So how do we do this with jQuery? Since we&#8217;re posting data, we use the <code>$.post</code> function. It looks a little like this:</p>
<pre class="brush: jscript; title: ; notranslate">
$.post('file.php', {
						
	information        : 'to be sent',
	to                 : 'file'
					    
	}, function(data) {
		
	}	
						
});

</pre>
<p>So in the above example we end the information (thats the bit inside the first set of curly brackets) to the file, file.php. When the information is sent it will return some information in the form of a data variable, and we can then use that data to return information to the user via Javascript. </p>
<h2>The ajax file</h2>
<p>The ajax file is going to have to be customized to fit your needs. All you have to do is grab some information from the MySQL database of your choice with some PHP. I have created a very basic ajax.php file that grabs information from a wordpress MySQL database and displays the content with the title and link. It looks a little like this, but it will be included with the download files in the download link above.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

mysql_connect('localhost', 'username', 'password') or die();
mysql_select_db('database');

$offset = is_numeric($_POST['offset']) ? $_POST['offset'] : die();
$postnumbers = is_numeric($_POST['number']) ? $_POST['number'] : die();


$run = mysql_query(&quot;SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type ='post' ORDER BY id DESC LIMIT &quot;.$postnumbers.&quot; OFFSET &quot;.$offset);


while($row = mysql_fetch_array($run)) {
	
	$content = substr(strip_tags($row['post_content']), 0, 500);
	
	echo '&lt;h1&gt;&lt;a href=&quot;'.$row['guid'].'&quot;&gt;'.$row['post_title'].'&lt;/a&gt;&lt;/h1&gt;&lt;hr /&gt;';
	echo '&lt;p&gt;'.$content.'...&lt;/p&gt;&lt;hr /&gt;';

}

?&gt;
</pre>
<h2>Using the Plugin</h2>
<p>Once you have your ajax file sorted out, its just a case of running the plugin. There are a bunch of variables you can determine, <strong>but it&#8217;s important that you define the query if you&#8217;re using the original ajax.php file listed above</strong>.</p>
<p>To run the plugin just upload all the files and create a container in your HTML called <code>#content</code> or whatever you want to call your container. Then run the plugin on that. Easy!</p>
<pre class="brush: jscript; title: ; notranslate">


$(document).ready(function() {

	$('#content').scrollPagination({

		nop     : 10, // The number of posts per scroll to be loaded
		offset  : 0, // Initial offset, begins at 0 in this case
		error   : 'No More Posts!', // When the user reaches the end this is the message that is
		                            // displayed. You can change this if you want.
		delay   : 500, // When you scroll down the posts will load after a delayed amount of time.
		               // This is mainly for usability concerns. You can alter this as you see fit
		scroll  : true // The main bit, if set to false posts will not load as the user scrolls. 
		               // but will still load if the user clicks.
		
	});
	
});

</pre>
<p>In the download you&#8217;ll find the files necessary to do everything I&#8217;ve shown you. Since I can&#8217;t include database details you will have to supply your own which you can edit in the ajax.php file. And that&#8217;s it! Have a good day!</p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3542&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=1qN_hRzi8y8:wNd-y0Z8lGk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=1qN_hRzi8y8:wNd-y0Z8lGk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=1qN_hRzi8y8:wNd-y0Z8lGk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=1qN_hRzi8y8:wNd-y0Z8lGk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=1qN_hRzi8y8:wNd-y0Z8lGk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/1qN_hRzi8y8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/01/scroll-pagination/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/01/scroll-pagination/</feedburner:origLink></item>
		<item>
		<title>iPhone Style Dragging for Both Desktop and Mobile with jQuery</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/lGqCaT7qm3Q/</link>
		<comments>http://www.inserthtml.com/2013/01/touch-drag-movement-html5/#comments</comments>
		<pubDate>Tue, 08 Jan 2013 17:31:02 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3546</guid>
		<description><![CDATA[When we create stuff for the web now it&#8217;s important we remember that the web has spread from the trackpad and mouse to the touch screen. Sometimes this is hard to accomodate for, but it&#8217;s not that hard to create some awesome cross device friendly touch and drag events with HTML5 and some smart styling! Getting Started I&#8217;ve made a&#8230;]]></description>
				<content:encoded><![CDATA[<p>When we create stuff for the web now it&#8217;s important we remember that the web has spread from the trackpad and mouse to the touch screen. Sometimes this is hard to accomodate for, but it&#8217;s not that hard to create some awesome cross device friendly touch and drag events with HTML5 and some smart styling!</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/12/image.jpg" alt="image" width="646" height="500" class="aligncenter size-full wp-image-3587" />
</div>
<h2>Getting Started</h2>
<p>I&#8217;ve made a little plugin that lets you grab and drag your way through a bunch of pictures of album artwork, similar to you drag through objects on an iphone at the start screen. Check out the demo to get a feel for what we&#8217;re going to be creating. The plugin isn&#8217;t too difficult to understand and you can download the finished version above, but when I first designed it, it only worked with mouse drags.</p>
<pre class="brush: jscript; title: ; notranslate">
$this.mousemove(function() {

});
</pre>
<p>So first off we need to alter this so that it&#8217;s mobile compatible. That&#8217;s not too difficult to do, we just need to use bind and we can bind multiple event handlers to a single element using the same function. Chances are the function you&#8217;re using isn&#8217;t going to be changing that significantly from mobile to desktop so this is quite beneficial. </p>
<pre class="brush: jscript; title: ; notranslate">
$this.bind('mousemove touchmove', function() {

});
</pre>
<p>Voila! Now our function is totally compatible with mobiles. In our particular plugin we have to check where the user is clicking in the object. Usually this would be done with <code>e.pageX</code> but on mobile it&#8217;s a little more complicated. This is what I initially wrote (for desktop only compatibility):</p>
<pre class="brush: jscript; title: ; notranslate">
firstPositionX = e.pageX - $this.offset().left;
</pre>
<p>This is the first position the user clicks. Now when it comes to mobile, this will be undefined. So all we have to do is say if e.pageX is undefined, then use the mobile version of e.pageX:</p>
<pre class="brush: jscript; title: ; notranslate">
if(e.pageX == undefined) firstPositionX = e.originalEvent.touches[0].pageX - $this.offset().left;
else firstPositionX = e.pageX - $this.offset().left;
</pre>
<h2>Adjusting the CSS</h2>
<p>Now the next problem is that the interface is still scaled for desktop screens. To fix that we need to alter the CSS a little. On a mobile device, we should ignore all default settings and just set the width to the width of the device. We also need to alter the padding a little.</p>
<pre class="brush: css; title: ; notranslate">
@media only screen and (max-device-width: 480px) { 

	.drag {
		width: 100% !important;
		height: 100% !important;
		border-radius: 0;
		margin: 0 !important;
	}
	
	.drag .item {
		margin: 7px 11px;
		opacity: 1;
	}
	
}
</pre>
<p>And now we have something that will work on most devices!</p>
<h2>How the plugin works</h2>
<p>The plugin provides a way to use your mouse to drag a bunch of icons in a similar fashion to what you&#8217;d expect on an iPhone. It has a bunch of settings and can be further customized with CSS. To use the plugin all you have to do is include it and a jQuery file file and then run this little snippet of Javascript:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {

	$('.content').dragSensitive({
	
		// The length of every row. Default is 10 items per row
		rowLength : 10,
		
		// The default width of the box. 
		boxWidth  : 500,
		
		// The default height of the box.
		boxHeight : 500,
		
		// The rate at which grabbing pans across items
		// The default is 1.3. Increasing makes it go slower.
		rate      : 1.3,
		
		// Sets whether or not the UI will snap to the last
		// element when the user stops grabbing
		round     : true,
		
		// This amount a user can drag (in pixels) while still
		// being able to click an object. Usually clicking is
		// disabled on drag, but within a (by default) 20px movement
		// clicking will still be enabled
		mistake   : 20
		
	});

});
</pre>
<p>The settings do not have to be altered, and in fact you can run the plugin without even mentioning them, but they are shown above for reference. Your HTML would then look something like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;content&quot;&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;div class=&quot;itemcontent&quot;&gt;&lt;a href=&quot;hey!&quot;&gt;Some Content&lt;/a&gt;&lt;/div&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;div class=&quot;item&quot;&gt; &lt;/div&gt;
	&lt;!-- .. Etc, etc. ------&gt;
&lt;/div&gt;
</pre>
<p>Each item represents a single icon or block in your drag box. If you put a div with the class <code>itemcontent</code> inside an item this content will be shown on the back of the icon when it flips over. Otherwise a generic play button will be shown. </p>
<p>You can download the files required to run this (I&#8217;ve annotated the code so you can understand what&#8217;s happening), or alternatively just check out the demo. <strong>I have tested this in the latest version of all browsers and it seems to work fine</strong>. Feel free to ask any questions in the comments, and have a good day!</p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3546&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=lGqCaT7qm3Q:aph_nf8tbvk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=lGqCaT7qm3Q:aph_nf8tbvk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=lGqCaT7qm3Q:aph_nf8tbvk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=lGqCaT7qm3Q:aph_nf8tbvk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=lGqCaT7qm3Q:aph_nf8tbvk:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/lGqCaT7qm3Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/01/touch-drag-movement-html5/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/01/touch-drag-movement-html5/</feedburner:origLink></item>
		<item>
		<title>The Best of Responsive Web Design 2012</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/LW4XCKDqcas/</link>
		<comments>http://www.inserthtml.com/2013/01/responsive-design-2012/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 18:00:05 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[inspiration]]></category>
		<category><![CDATA[responsive]]></category>
		<category><![CDATA[roundup]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3651</guid>
		<description><![CDATA[In the past year we have seen the rapid movement of mainstream and general web design to responsive CSS and HTML. This has been a boon for the mobile web industry, and provided us with websites we can actually use on mobile devices(!) In this roundup we&#8217;re going to look at some of the best implementations of responsiveness in the&#8230;]]></description>
				<content:encoded><![CDATA[<p>In the past year we have seen the rapid movement of mainstream and general web design to responsive CSS and HTML. This has been a boon for the mobile web industry, and provided us with websites we can actually use on mobile devices(!) In this roundup we&#8217;re going to look at some of the best implementations of responsiveness in the past year. Who knows what the next year will bring!</p>
<h2>Common Features</h2>
<p>A few common features have appeared over the last year that are becoming more mainstream in their application. The following are trends we have seen in 2012 and are likely to continue into 2013. </p>
<h3>3 Bar Drop Down</h3>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2013/01/image.jpg" alt="" width="600" height="200" />
</div>
<p>The 3 bar icon, representing a drop down menu has grown to become a staple for most web designers working on the responsive web. Some might say it&#8217;s a little ambiguous and maybe better to avoid, but this has not stopped people from applying it to many of their designs.</p>
<h3>Slide Out Menu</h3>
<div class="image">
   <a href="http://www.mashable.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2013/01/image-2.jpg" alt="" width="398" height="200" /></a><br />
   <span><a href="http://www.mashable.com/">Mashable is just one of the sites to adopt this</a></span>
</div>
<p>Some websites have adopted a Facebook App-esque slide out panel for their menu. This is actually a pretty awesome addition to your mobile web application which you might be inspired to implement into your designs.</p>
<h3>Mixed Feelings on Fixed Headers</h3>
<div class="image">
   <a href="http://www.thenextweb.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2013/01/image-3.jpg" alt="" width="398" height="200" /></a><br />
   <span><a href="http://www.thenextweb.com/">The Next Web uses a fixed header</a></span>
</div>
<p>Fixed headers on mobile devices seem to be receiving mixed feelings. On one hand a fixed header allows users to quickly navigate around the site, but on the other, screen space on mobile devices is very limited. Depending on your project you might have different feelings.</p>
<h1>Roundup <span class="tk-museo-sans">Below is a roundup of some of the best examples of responsive design from 2012. Enjoy!</span></h1>
<h3 class="roundup-title"><a href="http://worldwildlife.org/">World Wild Life</a></h3>
<div class="image">
<a href="http://worldwildlife.org/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/1a1.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://worldwildlife.org/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/1b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.bostonglobe.com/">Boston Globe</h3>
<div class="image">
<a href="http://www.bostonglobe.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/2a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.bostonglobe.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/2b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.mashable.com/">Mashable</h3>
<div class="image">
<a href="http://www.mashable.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/3a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.mashable.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/3b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://2012.inspireconf.com/">Inspire Conference</h3>
<div class="image">
<a href="http://2012.inspireconf.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/4a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://2012.inspireconf.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/4b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://dressresponsively.com/">Dress Responsively</h3>
<div class="image">
<a href="http://dressresponsively.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/5a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://dressresponsively.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/5b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.humaan.com.au/">Humaan</h3>
<div class="image">
<a href="http://www.humaan.com.au/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/6a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.humaan.com.au/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/6b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.microsoft.com/en-us/default.aspx">Microsoft</h3>
<div class="image">
<a href="http://www.microsoft.com/en-us/default.aspx"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/7a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.microsoft.com/en-us/default.aspx"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/7b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://createdm.com/">CreateDM</h3>
<div class="image">
<a href="http://createdm.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/8a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://createdm.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/8b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://happycog.com/">Happy Cog</h3>
<div class="image">
<a href="http://happycog.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/9a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://happycog.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/9b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://thegreatdiscontent.com/">The Great Discontent</h3>
<div class="image">
<a href="http://thegreatdiscontent.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/10a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://thegreatdiscontent.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/10b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://thenextweb.com/">The Next Web</h3>
<div class="image">
<a href="http://thenextweb.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/11a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://thenextweb.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/11b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://viljamis.com/">Viljami S</h3>
<div class="image">
<a href="http://viljamis.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/12a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://viljamis.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/12b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://grainandmortar.com/">Grain and Mortar</h3>
<div class="image">
<a href="http://grainandmortar.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/13a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://grainandmortar.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/13b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://badracket.com/">Bad Racket</h3>
<div class="image">
<a href="http://badracket.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/14a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://badracket.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/14b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://danielvane.com/">Daniel Vane</h3>
<div class="image">
<a href="http://danielvane.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/15a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://danielvane.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/15b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://5dinstitute.org/">5D Institution</h3>
<div class="image">
<a href="http://5dinstitute.org/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/16a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://5dinstitute.org/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/16b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://getflywheel.com/">Fly Wheel</h3>
<div class="image">
<a href="http://getflywheel.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/17a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://getflywheel.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/17b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://foodsense.is/">Food Sense</h3>
<div class="image">
<a href="http://foodsense.is/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/18a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://foodsense.is/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/18b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://envylabs.com/">Envy Labs</h3>
<div class="image">
<a href="http://envylabs.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/19a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://envylabs.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/19b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://mapbox.com/">Map Box</h3>
<div class="image">
<a href="http://mapbox.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/20a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://mapbox.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/20b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</h3>
<div class="image">
<a href="http://twitter.github.com/bootstrap/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/21a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://twitter.github.com/bootstrap/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/21b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.unitedpixelworkers.com/">United Pixel Workers</h3>
<div class="image">
<a href="http://www.unitedpixelworkers.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/22a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.unitedpixelworkers.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/22b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://oliverrussell.com/">Oliver Russel</h3>
<div class="image">
<a href="http://oliverrussell.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/23a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://oliverrussell.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/23b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.collectiveboom.com/">Collective Boom</h3>
<div class="image">
<a href="http://www.collectiveboom.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/24a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.collectiveboom.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/24b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.pixelstadium.com/">Pixel Stadium</h3>
<div class="image">
<a href="http://www.pixelstadium.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/25a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.pixelstadium.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/25b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://skinnyties.com/">Skinny Ties</h3>
<div class="image">
<a href="http://skinnyties.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/26a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://skinnyties.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/26b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.indochino.com/">Indochino</h3>
<div class="image">
<a href="http://www.indochino.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/27a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.indochino.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/27b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://lorenzoverzini.com/">Lorenzo Verzini</h3>
<div class="image">
<a href="http://lorenzoverzini.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/28a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://lorenzoverzini.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/28b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.designweekportland.com/">Design Week Portland</h3>
<div class="image">
<a href="http://www.designweekportland.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/29a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.designweekportland.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/29b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://grkfresh.com/">GRK Fresh</h3>
<div class="image">
<a href="http://grkfresh.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/30a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://grkfresh.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/30b.jpg" width="399" height="512" alt="" /></a>
</div>
<h3 class="roundup-title"><a href="http://www.wearemovingthings.com/">We Are Moving Things</h3>
<div class="image">
<a href="http://www.wearemovingthings.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/31a.jpg" width="594" height="322" alt="" /></a></p>
<p><a href="http://www.wearemovingthings.com/"><img src="http://www.inserthtml.com/wp-content/uploads/2012/12/31b.jpg" width="399" height="512" alt="" /></a>
</div>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3651&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=LW4XCKDqcas:XsF65JE_FZg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LW4XCKDqcas:XsF65JE_FZg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LW4XCKDqcas:XsF65JE_FZg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=LW4XCKDqcas:XsF65JE_FZg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LW4XCKDqcas:XsF65JE_FZg:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/LW4XCKDqcas" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2013/01/responsive-design-2012/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2013/01/responsive-design-2012/</feedburner:origLink></item>
		<item>
		<title>CSS3 Regions and Flow</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/WhZrseGI17s/</link>
		<comments>http://www.inserthtml.com/2012/10/css3-regions-flow/#comments</comments>
		<pubDate>Tue, 09 Oct 2012 16:46:51 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[regions]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3470</guid>
		<description><![CDATA[Put simply, CSS3 regions associate boxes and blocks with other blocks to allow a designer to make content flow from one box into another automatically. Previously this was impossible with just CSS. The CSS3 Regions Specification expands CSS further from a static design to a more responsive and future proof language. This article is about new CSS which may not&#8230;]]></description>
				<content:encoded><![CDATA[<p>Put simply, CSS3 regions associate boxes and blocks with other blocks to allow a designer to make content flow from one box into another automatically. Previously this was impossible with just CSS. The CSS3 Regions Specification expands CSS further from a static design to a more responsive and future proof language.</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/10/feature.jpg" alt="" width="648" height="484" />
</div>
<div class="alert">
    This article is about new CSS which may not be supported in every browser! Be careful.
</div>
<h2>What are regions</h2>
<p>Put simply, regions are a way in CSS to allow content to flow from one box to another. <strong>This tutorial will show you how regions work according to the current specification.</strong> Currently regions are available in the nightly build of webkit and in the platform preview of IE. </p>
<h3>Enabling Regions</h3>
<p>We&#8217;re going to be using Google Chrome as the web browser of choice for this tutorial as it has the greatest support for this feature. For some odd reason Chrome has regions disabled, so we need to go and enable it by going to <a href="chrome://flags">chrome://flags</a></p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/10/image-1.jpg" width="448" height="251" alt="" />
</div>
<h2>How it works</h2>
<p>Effectively there are two key properties to a region flow. Those are the <code>flow-in</code> and <code>flow-out</code>. Now pay attention, because this can be a little tricky to wrap your head around. The basic principle is that we can allow content to flow from one block to another. <strong>The content of a specified div will go from one div to the other, &#8216;flowing&#8217; between them, rather than having to put specific content in each div separately.</strong></p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/10/image-2.gif" width="600" height="400" alt="" />
</div>
<p><strong>The idea is that we will have one block which contains the content, and &#8216;flow&#8217; the content from that block into several other blocks.</strong> The content will still be contained within the primary container physically, but it will be diverted to flow through other block elements. </p>
<h3>Keywords</h3>
<p>For a flow to work we give it a keyword. A keyword identifies which items will flow into which containers. So suppose we have something like this in HTML:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;source-1&quot;&gt;
    &lt;p&gt; [ Really long article goes here ] &lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;container&quot;&gt;
    &lt;div id=&quot;region1&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;region2&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
    &lt;div id=&quot;region3&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

</pre>
<p>We can set it up so the article source will &#8216;flow&#8217; into the regions. Note that the source div will effectively disappear since the content will be moved into the regions. For this particular example we&#8217;ll use the keyword &#8216;main&#8217;. You can use any keyword you want, it doesn&#8217;t really matter. Just make sure the content and the objects you want the content to flow into use the same keyword.</p>
<p>So the content will flow into this hypothetical &#8216;main&#8217; container and then flow out again into the regions. Although this isn&#8217;t necessarily completely accurate it is an easy way to think about it.</p>
<pre class="brush: css; title: ; notranslate">
#source-1 {
	-webkit-flow-into: main;
}

.region {
	-webkit-flow-from: main;
	width: 250px;
	float: left;
	margin-right: 10px;
	background: #eee;
	width: 30%;
	padding: 1%;
	margin-right: 1%;
	height: 400px;
}
</pre>
<p><strong>You can have multiple things flowing into one container.</strong> They will appear one after the other in the flow. So you could have two sources, or other content which will be added on to the flow.</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/10/image-3.gif" width="672" height="227" alt="" />
</div>
<h2>Styling the flow</h2>
<p>It becomes very easy to style the flow containers with the <code>@region</code> tag. All you need to do is target the element and style as you see fit. For example, you can target the HTML in the first region in the code above like so:</p>
<pre class="brush: css; title: ; notranslate">
@region #region1 {
    p { ... }
}
</pre>
<p>What is the benefit to using this? It means you can style content that passes through multiple regions. <strong>You could highlight the first paragraph which may appear in two regions.</strong></p>
<h2>An Example</h2>
<p>To help show you exactly how this all works, lets try a simple example. We have a layout in HTML like this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;content&quot;&gt;
    &lt;div id=&quot;source&quot;&gt;
        [ ARTICLE GOES HERE ]
    &lt;/div&gt;
    
    &lt;div class=&quot;one-column&quot;&gt;
    	&lt;div id=&quot;region1&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;three-column&quot;&gt;
	    &lt;div id=&quot;region2&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	    &lt;div id=&quot;region3&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	    &lt;div id=&quot;region4&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;two-column&quot;&gt;
		&lt;div id=&quot;region5&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
		&lt;div id=&quot;region6&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
	&lt;div class=&quot;one-column-last&quot;&gt;
		&lt;div id=&quot;region7&quot; class=&quot;region&quot;&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;
</pre>
<p>You can put the article in the <code>.source</code> div if you want. Make sure it&#8217;s really long! Every <code>.region</code> div represents a single flow of content. That means we&#8217;re going to make the content flow from one to the other. Create a CSS file and put the following in it:</p>
<pre class="brush: css; title: ; notranslate">
body {
	font-family: Georgia, serif;	
	margin: 0;
}

.content {
	padding: 2% 0 2% 2%;
}

#source {
	line-height: 26px;
	text-align: justify;
	-webkit-flow-into: main;
}

p {
	margin: 0;
	padding: 0;
	text-transform: capitalize;
}

.region {
	-webkit-flow-from: main;
	float: left;
	padding: 1%;
	margin-right: 1%;
}

.one-column .region {
	width: 96%;
	height: 200px;
}

.three-column .region {
	width: 30%;
	border-top: 2px solid #eee;
	border-bottom: 2px solid #eee;
	margin-right: 10px 1% 10px 0;
	height: 200px;
}

.two-column .region {
	width: 46.5%;
	height: 300px;
}

.one-column-last .region {
	width: 96%;
	height: 600px;
	font-weight: bold;
	font-style: italic;
}
</pre>
<p><strong>The important lines to note are the flow from and flow into lines in .region and #source</strong>. The content flows from the source to &#8216;main&#8217;, and then from &#8216;main&#8217; to the regions. Pretty simple, huh? </p>
<p>Support is currently pretty bad with you needing to enable it in chrome. The platform preview of IE also supports regions, which is a big plus. However, it is totally unrealistic that you would use this in a real life project. It is nice, though, to see what is under development in web design.</p>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3470&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=WhZrseGI17s:PZWsGwvwdEI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WhZrseGI17s:PZWsGwvwdEI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WhZrseGI17s:PZWsGwvwdEI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=WhZrseGI17s:PZWsGwvwdEI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=WhZrseGI17s:PZWsGwvwdEI:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/WhZrseGI17s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2012/10/css3-regions-flow/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2012/10/css3-regions-flow/</feedburner:origLink></item>
		<item>
		<title>CSS3 Conditional Statements</title>
		<link>http://feedproxy.google.com/~r/inserthtml/~3/LpEWoCLBXkE/</link>
		<comments>http://www.inserthtml.com/2012/09/css3-conditional-statements/#comments</comments>
		<pubDate>Mon, 24 Sep 2012 13:23:14 +0000</pubDate>
		<dc:creator>Johnny Simpson</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[future-css]]></category>

		<guid isPermaLink="false">http://www.inserthtml.com/?p=3411</guid>
		<description><![CDATA[In times gone by a web designer had only the properties and values in his head to style a website. Nowadays however, things are a little more complex, and they&#8217;re about to get even more so with the CSS Working Group&#8217;s conditional CSS statements. This article is about new CSS which may not be supported in every browser! Be careful.&#8230;]]></description>
				<content:encoded><![CDATA[<p>In times gone by a web designer had only the properties and values in his head to style a website. Nowadays however, things are a little more complex, and they&#8217;re about to get even more so with the CSS Working Group&#8217;s conditional CSS statements.</p>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/09/featured-1-1.jpg" alt="" width="545" height="407" />
</div>
<div class="alert">
    This article is about new CSS which may not be supported in every browser! Be careful.
</div>
<p>I say almost introductory because you might have heard of these new things called media queries. <strong>Media queries are a type of conditional statement where you can style a webpage based on the properties of a user&#8217;s computer</strong>. For example, one might say the following in their CSS stylesheet:</p>
<pre class="brush: css; title: ; notranslate">
@media screen and (min-width: 1000px) {

   /* CSS Goes here! */

}
</pre>
<p>The stuff you put in the curly brackets will only apply to <strong>screens</strong> with a <strong>width greater than 1000px</strong>. There are a bunch of other media queries regarding resolution, etc. I&#8217;m sure you&#8217;re quite familiar with them. What you may not know however is the CSS Conditional Statement Specification also talks about two other CSS conditional statements. Currently these two features are only supported in Firefox (6.0 for @document and 17.0 for @supports)</p>
<h2>@supports</h2>
<div class="image">
    <img src="http://www.inserthtml.com/wp-content/uploads/2012/09/supports.jpg" alt="" width="600" height="400" />
</div>
<p>Suppose a particular brand of browser supports a feature, but another doesn&#8217;t. You then have a back up CSS script planned for browsers that do not support that particular feature. Well, <code>@supports</code> can help you with that! <strong>@supports checks to see if the property you call is supported in the browser</strong>. </p>
<p>So lets say (for some reason) you only want CSS to apply to a browser with the CSS flexible box model supported. You might do something like this:</p>
<pre class="brush: css; title: ; notranslate">
@supports (display: flex) {
    /* Put some CSS here */
}
</pre>
<p>The CSS in the curly brackets will only be enabled should the browser support the flex box. Then you can have other CSS which overrides that CSS should the browser not support the flex box, i.e.:</p>
<pre class="brush: css; title: ; notranslate">
/* If flexbox isn't supported, backup CSS goes here */

@supports (display: flex) {
    /* Flexible box CSS goes here */
}

</pre>
<p>Similar to media queries, you can check for multiple things using <code>or</code> and <code>and</code>.</p>
<pre class="brush: css; title: ; notranslate">
@supports (display: flex) and (box-shadow: 0 0 10px rgba(0,0,0,0.1)) { 
    /* If box shadows and the flex box are supported */
}
@supports ((display: flex) and (animation-duration: 1s)) or ((diplay: flex) and (transition-duration: 1s)) {
    /* If flex box and animation duration are supported, or if flex box and transition duration are supported */
}
</pre>
<h3>Negation</h3>
<p>You can check if a browser doesn&#8217;t support a feature too using <code>not()</code>. For example, the CSS in the curly brackets below will only be applicable when flexbox isn&#8217;t supported:</p>
<pre class="brush: css; title: ; notranslate">
@supports not(display: flex) {
    /* Back up CSS goes here */
}
</pre>
<h2>@document</h2>
<div class="image">
   <img src="http://www.inserthtml.com/wp-content/uploads/2012/09/document-1.png" alt="" width="600" height="400" />
</div>
<p><strong>@document styles CSS based on the page you are on</strong>. For example, it would be totally possible to do this to target a specific URL with CSS:</p>
<pre class="brush: css; title: ; notranslate">
@document url('http://www.inserthtml.com/') {
    /* CSS goes here */
}
</pre>
<p>Or you could apply it to everything in a particular folder:</p>
<pre class="brush: css; title: ; notranslate">
@document url-prefix('http://www.inserthtml.com/css') {
    /* CSS goes here */
}
</pre>
<h2>The Benefits</h2>
<h3>Faster loading times</h3>
<p>Presumably you can use this little trick to have a single unified header which selects which files to include based more on the user&#8217;s browser&#8217;s capabilities. For example, lets suppose you have some additional extras (box shadows, border-radius, etc), which are intended for newer browsers. When it comes to IE this can be a big problem because IE doesn&#8217;t support a lot of these features but you still have to load the CSS file. Using <code>@supports</code> you could reduce your primary CSS file and include the added extras as necessary in separate CSS files, <strong>thus improving page load times</strong>.</p>
<pre class="brush: css; title: ; notranslate">

&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot; /&gt;

&lt;!-- Optional extras --&gt;
&lt;style&gt;
 
@supports (box-shadow: 0 0 10px rgba(0,0,0,0.1)) {
    @import url('box-shadow.css');
}

&lt;/style&gt;
</pre>
<h3>One Stylesheet for everything</h3>
<p>Alternatively, you can have one stylesheet for everything since you can load the page specific and support specific CSS within these conditional statements. <strong>This is a good idea since the single CSS file will be stored in the user&#8217;s cache, so the page will load faster after the first visit</strong>.</p>
<pre class="brush: css; title: ; notranslate">

/* Some regular CSS here */
div {
   ...
}

@supports (display: flexbox) {
    /* If supported, do this CSS */
}

@document url('http://www.inserthtml.com/page.html') {
    /* CSS for specific page */
} 

@media print {
    /* Media CSS */
}

</pre>
<h2>Current Support</h2>
<table class="support2" cellspacing="0">
<tr>
<td>Feature</td>
<td>Chrome</td>
<td>Safari</td>
<td>Firefox</td>
<td>IE</td>
<td>Opera</td>
</tr>
<tr>
<td>@document</td>
<td>None</td>
<td>None</td>
<td class="s">6.0</td>
<td>None</td>
<td>None</td>
</tr>
<tr>
<td>@supports</td>
<td>None</td>
<td>None</td>
<td class="s">17.0</td>
<td>None</td>
<td>None</td>
</tr>
</table>
<img src="http://www.inserthtml.com/?ak_action=api_record_view&id=3411&type=feed" alt="" /><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/inserthtml?a=LpEWoCLBXkE:x410ffWOa9Y:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LpEWoCLBXkE:x410ffWOa9Y:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LpEWoCLBXkE:x410ffWOa9Y:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/inserthtml?i=LpEWoCLBXkE:x410ffWOa9Y:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/inserthtml?a=LpEWoCLBXkE:x410ffWOa9Y:7Q72WNTAKBA"><img src="http://feeds.feedburner.com/~ff/inserthtml?d=7Q72WNTAKBA" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/inserthtml/~4/LpEWoCLBXkE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.inserthtml.com/2012/09/css3-conditional-statements/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		<feedburner:origLink>http://www.inserthtml.com/2012/09/css3-conditional-statements/</feedburner:origLink></item>
	</channel>
</rss>
