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

<channel>
	<title>Decodize</title>
	<atom:link href="http://www.decodize.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.decodize.com</link>
	<description>Bits of front-end development</description>
	<lastBuildDate>Sun, 06 May 2012 20:12:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to build a nodejs npm package from scratch.</title>
		<link>http://www.decodize.com/javascript/build-nodejs-npm-installation-package-scratch/</link>
		<comments>http://www.decodize.com/javascript/build-nodejs-npm-installation-package-scratch/#comments</comments>
		<pubDate>Sun, 06 May 2012 20:04:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[javaScript]]></category>
		<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=304</guid>
		<description><![CDATA[Aim is to create a node package and publish it in npm registery. This is a simple example code with which you can understand all the process involved to create, install and publish node packages. What is nodejs? Hmm.. you &#8230; <a href="http://www.decodize.com/javascript/build-nodejs-npm-installation-package-scratch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2 class="highlight">Aim is to create a node package and publish it in npm registery. This is a simple example code with which you can understand all the process involved to create, install and publish node packages.</h2>
<h3>What is nodejs?</h3>
<p>Hmm.. you will get plenty of good resources when you google it with this keyword. Start by installing it from here : <a href="http://node.org">nodejs</a></p>
<p><span id="more-304"></span></p>
<h3>What is npm?</h3>
<p><a href="http://npmjs.org/">Node package manager</a> and it is used to add or remove node applications. It came as a default package in newer node installations, both windows and mac. Install it on other platforms by refering this <a href="https://github.com/isaacs/npm">resource</a>. Check out all the <a href="http://search.npmjs.org/"> npm registry entries here</a></p>
<p>Install your fevorite application &#8211; <code>npm install app-name</code>.<br />
Example:- <code>npm install jsbeautify</code></p>
<h3>First node program</h3>
<p><strong>Prerequisite</strong></p>
<ul>
<li>Install nodejs</li>
<li>Github account <small>[Optional]</small></li>
</ul>
<p><strong>Objective:</strong> Create a nodejs application that reads a file and replace all the matching text in it with the one that you pass as an argument.</p>
<p>Eg:- readme.txt content &#8211; &#8220;Drink like a dog&#8221;</p>
<p><code>replaceme readme.txt dog cat</code></p>
<p>//out.txt &#8211; Drink like a cat</p>
<p>Agenda</p>
<ul>
<li><a href="#base">Setting up base &#8211; folder structure</a></li>
<li><a href="#modules">Creating node modules and require it in other modules</a></li>
<li><a href="#readwirte">Read &amp; write file using node</a></li>
<li><a href="#args">Passing arguments from CLI</a></li>
<li><a href="#json">Creating package.json</a></li>
<li><a href="#package">Packaging application</a></li>
<li><a href="#npm">Adding users to npm registry</a></li>
<li><a href="#publish">Publishing application</a></li>
<li><a href="#uninstall">Uninstallling application from system</a></li>
<li><a href="#unpublish">Unpublishing application from npm registry</a></li>
</ul>
<p><a id="base"> </a></p>
<h3>Setting up base &#8211; folder structure</h3>
<p>Application&#8217;s folder structure as follows.</p>
<pre>replaceme
   - bin
   --- replaceme.js
   - lib
   --- main.js
   --- replace.js
   package.json
   README.md</pre>
<p>Open cmd and type <code>mkdir replaceme &amp;&amp; cd replaceme &amp;&amp; mkdir bin &amp;&amp; mkdir lib</code>. Create replacement.js, main.js and replace.js inside respective folders.</p>
<p><strong>Create replace function</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">var <span style="color: #993333;">text</span> <span style="color: #00AA00;">=</span> <span style="color: #ff0000;">&quot;To live long, eat like a cat, drink like a dog.&quot;</span><span style="color: #00AA00;">;</span>
var out <span style="color: #00AA00;">=</span> text.replace<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'cat'</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">'dog'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
console.log<span style="color: #00AA00;">&#40;</span>out<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>Run it with c:\&gt;replaceme\lib\&gt;<code> node replace.js <strong></strong></code></p>
<p>//Output &#8211; To live long, eat like a dog, drink like a dog.</p>
<p><a id="modules"> </a><br />
<strong>Node modules</strong></p>
<p>Next step is to convert above code into a node module so that we can require it in other js/modules. Incuding an external javascript in our document is simple &#8211; require(&#8216;modulejs&#8217;);.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">//replaceme<span style="color: #6666ff;">.js</span>
exports<span style="color: #6666ff;">.replaceme</span> <span style="color: #00AA00;">=</span> function<span style="color: #00AA00;">&#40;</span><span style="color: #993333;">text</span><span style="color: #00AA00;">,</span> vala<span style="color: #00AA00;">,</span> valb<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
	function out<span style="color: #00AA00;">&#40;</span>val<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
		return text.replace<span style="color: #00AA00;">&#40;</span>vala<span style="color: #00AA00;">,</span>valb<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
	return out<span style="color: #00AA00;">&#40;</span>vala<span style="color: #00AA00;">,</span>valb<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>exports.functionName</strong> &#8211; Its the simplest way to create a module &amp; now replaceme is a module. We can import it in main.js as require(&#8216;./replaceme&#8217;);</p>
<p>More informations on creating modules &#8211; <a href="http://book.mixu.net/ch8.html">check this link</a></p>
<p>c:\&gt;replaceme\lib\&gt;<code> node</code></p>
<p><code>&gt; re = require('./replaceme')</code></p>
<p><code>&gt; re.replaceme("The text to replace","replace","add")</code></p>
<p><strong>&gt; The text to add</strong></p>
<p>Our module is functioning now. Now create main.js.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">//main.js
&nbsp;
<span style="color: #00AA00;">&#40;</span>function<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
	//Declaring variables  
	var fs<span style="color: #00AA00;">,</span> reptxt<span style="color: #00AA00;">,</span> filedata<span style="color: #00AA00;">;</span>
&nbsp;
	//Requiring files
	fs <span style="color: #00AA00;">=</span> require<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'fs'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	reptxt <span style="color: #00AA00;">=</span> require <span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'./replaceme'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	//Reading file test<span style="color: #6666ff;">.txt</span>
	fs.readFile<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../test.txt&quot;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">'utf8'</span><span style="color: #00AA00;">,</span>function<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">,</span>data<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
	  if<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
		console.error<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;Could not open file: %s&quot;</span><span style="color: #00AA00;">,</span> err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		process.exit<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	 <span style="color: #00AA00;">&#125;</span>
	 //Calling replacement function
	 console.log<span style="color: #00AA00;">&#40;</span>reptxt.replaceme<span style="color: #00AA00;">&#40;</span>data<span style="color: #00AA00;">,</span><span style="color: #ff0000;">&quot;npm&quot;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">&quot;123&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span>.call<span style="color: #00AA00;">&#40;</span>this<span style="color: #00AA00;">&#41;</span></pre></div></div>

<p>Main.js reads file content and passes the content to replaceme function. It will output replaced string.</p>
<p><a id="readwirte"> </a><br />
<strong>Read file using node file module</strong></p>
<p>Now we have to write its out put into a file and save it in the same dir. It is also possible to overwrite the same file.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">//main.js
&nbsp;
<span style="color: #00AA00;">&#40;</span>function<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
	//Declaring variables  
	var fs<span style="color: #00AA00;">,</span> reptxt<span style="color: #00AA00;">,</span> filedata<span style="color: #00AA00;">;</span>
&nbsp;
	//Requiring files
	fs <span style="color: #00AA00;">=</span> require<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'fs'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	reptxt <span style="color: #00AA00;">=</span> require <span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'./replaceme'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	//Reading files
	fs.readFile<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../test.txt&quot;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">'utf8'</span><span style="color: #00AA00;">,</span>function<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">,</span>data<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
	  if<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
		console.error<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;Could not open file: %s&quot;</span><span style="color: #00AA00;">,</span> err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		process.exit<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	 <span style="color: #00AA00;">&#125;</span>
	 //Calling replacement function
	 filedata <span style="color: #00AA00;">=</span> reptxt.replaceme<span style="color: #00AA00;">&#40;</span>data<span style="color: #00AA00;">,</span><span style="color: #ff0000;">&quot;npm&quot;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">&quot;123&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	 //Writing replaced <span style="color: #993333;">text</span> into a new file
	fs.writeFile<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../out.txt&quot;</span><span style="color: #00AA00;">,</span> filedata<span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
		  	if<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
				console.error<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;Error saving file %s&quot;</span><span style="color: #00AA00;">,</span> err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
				process.exit<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		  	<span style="color: #00AA00;">&#125;</span>
			console.log<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'out.txt file saved!'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span>.call<span style="color: #00AA00;">&#40;</span>this<span style="color: #00AA00;">&#41;</span></pre></div></div>

<p>Now when we run node command <code>node main.js</code> you will see a new file named &#8216;out.txt&#8217;.</p>
<p><a id="args"> </a><br />
<strong>Passing arguments</strong></p>
<p>We neeed to pass our filename as an argument. &#8216;process.argv&#8217; used to catch arguments that passes through CLI. It gives us an array containing commandline arguments. We have to process this array &amp; get the required values.</p>
<p>Here in our example we are passing 3 arguments &#8216;the file, keyword, replace word&#8217; &#8211; <code>node main.js text.txt cat dog</code></p>
<p>This is the native way to parse commandline arguments. There are other libraries available for easy parsing of arguments [optimist, commander etc... ].</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">// print process<span style="color: #6666ff;">.argv</span> - node main<span style="color: #6666ff;">.js</span> ../text<span style="color: #6666ff;">.txt</span> cat dog
process<span style="color: #6666ff;">.argv</span>.forEach<span style="color: #00AA00;">&#40;</span>function <span style="color: #00AA00;">&#40;</span>val<span style="color: #00AA00;">,</span> index<span style="color: #00AA00;">,</span> array<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
  console.log<span style="color: #00AA00;">&#40;</span>index <span style="color: #00AA00;">+</span> <span style="color: #ff0000;">': '</span> <span style="color: #00AA00;">+</span> val<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
//Output
<span style="color: #cc66cc;">0</span><span style="color: #00AA00;">:</span> node
<span style="color: #cc66cc;">1</span><span style="color: #00AA00;">:</span> path/main<span style="color: #6666ff;">.js</span>
<span style="color: #cc66cc;">2</span><span style="color: #00AA00;">:</span> ../text<span style="color: #6666ff;">.txt</span>
<span style="color: #cc66cc;">3</span><span style="color: #00AA00;">:</span> cat
<span style="color: #cc66cc;">4</span><span style="color: #00AA00;">:</span> dog</pre></div></div>

<p>We need 2,3 &amp; 4 values. Note: its not a best practice to parsing parameter like this. Its better to use any node <a href="https://github.com/joyent/node/wiki/modules#wiki-parsers-commandline"> libraries.</a></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">&#40;</span>function<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
	//Declaring variables  
	var fs<span style="color: #00AA00;">,</span> reptxt<span style="color: #00AA00;">,</span> filedata<span style="color: #00AA00;">;</span>
&nbsp;
	//Requiring files
	fs <span style="color: #00AA00;">=</span> require<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'fs'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	reptxt <span style="color: #00AA00;">=</span> require <span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'./replaceme'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	//Reading files
	fs.readFile<span style="color: #00AA00;">&#40;</span>process.argv<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">,</span><span style="color: #ff0000;">'utf8'</span><span style="color: #00AA00;">,</span>function<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">,</span>data<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
	  if<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
		console.error<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;Could not open file: %s&quot;</span><span style="color: #00AA00;">,</span> err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		process.exit<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
	 <span style="color: #00AA00;">&#125;</span>
	 //Calling replacement function
	 filedata <span style="color: #00AA00;">=</span> reptxt.replaceme<span style="color: #00AA00;">&#40;</span>data<span style="color: #00AA00;">,</span>process.argv<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">,</span>process.argv<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	 //Writing replaced <span style="color: #993333;">text</span> into a new file
	fs.writeFile<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;../out.txt&quot;</span><span style="color: #00AA00;">,</span> filedata<span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
		  	if<span style="color: #00AA00;">&#40;</span>err<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span>
				console.error<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;Error saving file&quot;</span><span style="color: #00AA00;">,</span> err<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
				process.exit<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		  	<span style="color: #00AA00;">&#125;</span>
			console.log<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'out.txt file saved!'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
<span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">&#41;</span>.call<span style="color: #00AA00;">&#40;</span>this<span style="color: #00AA00;">&#41;</span></pre></div></div>

<p>Now we got 3 arguments &#8216;../text.txt, cat, dog&#8217;. <code>node main.js ../text.txt cat dog</code> this node command will read text.txt and replace all the &#8220;cat&#8221; text with &#8220;dog&#8221; and output the result in &#8216;out.txt&#8217;.</p>
<p><strong>Bin folder &#8211; replaceme file</strong></p>
<p>This file is the entry point. We point to this file from package.json.</p>
<pre class="css">    #!/usr/bin/env node
    var path = require('path');
    var fs = require('fs');
    var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
    require(lib + '/main.js');</pre>
<p><a id="publish"> </a></p>
<h3>Preparing to publish</h3>
<p><strong>Creating package.json</strong></p>
<p>This text file contains all the information about the project, like project path, dependencies, author name, tags, bug tracking info etc.. To create a package.json run <code>npm init</code> command from the root folder. It will ask series of questions and finally it will create package.json file.</p>
<p>Our package.json file will look like this.</p>
<pre class="css">{
  "author": "praveen vijayan ",
  "name": "replaceme",
  "description": "Node commandline application to replace selected text in a file.",
  "version": "0.1.1",
  "repository": {
    "url": ""
  },
  "main": "./lib/main",
  "bin": {
    "replaceme": "./bin/replaceme"
  },
  "dependencies": {},
  "devDependencies": {},
  "optionalDependencies": {},
  "engines": {
    "node": "*"
  }
}</pre>
<p><strong>Add new user to npm registry</strong></p>
<p><code>npm adduser</code><br />
Provide username &amp; email address. This command will register a new user into npm registry.</p>
<p><strong>Finally publish to npm registry</strong></p>
<p><code>npm publish</code> and test by installing it</p>
<p><code>npm install -g replaceme</code></p>
<p><a id="uninstall"> </a><br />
<strong>Uninstall node package</strong></p>
<p><code>npm uninstall -g replaceme</code></p>
<p><a id="unpublish"> </a><br />
<strong>Unpublish from npm registry</strong></p>
<p><code>npm unpublish replaceme@0.1.1</code></p>
<h3>Upload files into github</h3>
<p>It is not a compelsory part but it is a best practice to update your files to github and add links in package.json. Open README.md file created earlier and add basic info about your project using markdown syntax. Commit all files into git and activate issue tracker from account.</p>
<h3>Download files</h3>
<div class="demo">
<p><a href="http://www.decodize.com/demos/nodejs/replaceme.zip">Download files</a></p>
<p><a href="http://search.npmjs.org/#/replaceme">npm registry link</a></p>
</div>
<h4>happy nodding <img src='http://www.decodize.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </h4>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/javascript/build-nodejs-npm-installation-package-scratch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Weight scale using HTML5 drag &amp; drop and CSS3 rotation</title>
		<link>http://www.decodize.com/css/weight-scale-html5-drag-drop-css3-rotation/</link>
		<comments>http://www.decodize.com/css/weight-scale-html5-drag-drop-css3-rotation/#comments</comments>
		<pubDate>Sun, 01 Apr 2012 18:37:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[javaScript]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=250</guid>
		<description><![CDATA[Lets start with a demo (only works in chrome). Weight scale Usage Drag and drop weight block into scale [over doted outline]. Double click to remove a weight. Demo uses jQuery for DOM manipulation, css3 rotation for needle movement. HTML5 &#8230; <a href="http://www.decodize.com/css/weight-scale-html5-drag-drop-css3-rotation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.decodize.com/wp-content/uploads/2012/04/html5-drag-and-drop-css3-rotation-weight-scale.jpg" rel="lightbox"><img src="http://www.decodize.com/wp-content/uploads/2012/04/html5-drag-and-drop-css3-rotation-weight-scale-300x186.jpg" alt="" title="html5-drag-and-drop-css3-rotation-weight-scale" width="300" height="186" class="alignnone size-medium wp-image-279" /></a><br />
Lets start with a demo (only works in chrome). </p>
<div class="demo"><a href="http://www.decodize.com/demos/Weight%20scale%20using%20HTML5%20drag%20&#038;%20drop%20CSS3%20rotation/weight.html" title="HTML5 Drag and drop demo" target="_blank">Weight scale</a></div>
<p><strong>Usage</strong> Drag and drop weight block into scale [over doted outline]. Double click to remove a weight. Demo uses jQuery for DOM manipulation, css3 rotation for needle movement.<br />
<span id="more-250"></span><br />
<strong>HTML5 Drag and drop basics</strong> Before implementing <a href="http://html5please.com/#drag" title="HTML5 Drag and drop " target="_blank">check the readiness of drag and drop </a> Currently it better to use jQuery UI or other JavaScript libraries to do a better cross browser handling.</p>
<p>HTML5 Drag and drop based on the Microsoft IE&#8217;s original implementation (IE5 and up). Image and links are dragabble by default in browsers. Proof? try  drag and drop them in the address bar, you will be taken to the specified image/link. Set draggable=&#8221;true&#8221; in order to make other elements draggable.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;div draggable<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #00AA00;">&gt;</span>Im a draggable content&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Okay, now about drop zone. There is no droppable=&#8221;true&#8221;!!. We have to handle it via javascript events. Following are the events related to DnD.</p>
<ul>
<li>dragstart</li>
<li>drag</li>
<li>dragenter</li>
<li>dragleave</li>
<li>dragover</li>
<li>drop</li>
<li>dragend</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;div draggable<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;drag&quot;</span><span style="color: #00AA00;">&gt;</span>Im a draggable content&lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;dropzone&quot;</span><span style="color: #00AA00;">&gt;</span>Drop area&lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;script<span style="color: #00AA00;">&gt;</span>
var elem <span style="color: #00AA00;">=</span> document.getElementById<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'drag'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    elem.addEventListener<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dragstart'</span><span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>e<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
      //Do whatever on when user start dragging.
&nbsp;
    <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">,</span> false<span style="color: #00AA00;">&#41;</span>
&lt;/script<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Next step is to drop our dragged payload. We need 2 events (dragover and dragenter) in order to make an element drop capable.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;div draggable<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;drag&quot;</span><span style="color: #00AA00;">&gt;</span>Im a draggable content&lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;dropzone&quot;</span><span style="color: #00AA00;">&gt;</span>Drop area&lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;script<span style="color: #00AA00;">&gt;</span>
var elem <span style="color: #00AA00;">=</span> document.getElementById<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'drag'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">,</span>
    dropZone <span style="color: #00AA00;">=</span> document.getElementById<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dropzone'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    elem.addEventListener<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dragstart'</span><span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>e<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
      //Do whatever on when user start dragging.
    <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">,</span> false<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
elem.addEventListener<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dragenter'</span><span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>e<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
      //Things like visual cued for the drop zone can be added here.
    <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">,</span> false<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
elem.addEventListener<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dragover'</span><span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>e<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
     //Things like visual cued for the drop zone can be added here.
  <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">,</span> false<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
&nbsp;
&lt;/script<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Now we have to do the actual drop. &#8216;dataTransfer&#8217; holds the draged object. dataTransfer.getData(&#8216;text/html&#8217;) will get you the actual dragged element.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">var dropZone <span style="color: #00AA00;">=</span> document.getElementById<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'dropzone'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
 elem.addEventListener<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'drop'</span><span style="color: #00AA00;">,</span> function<span style="color: #00AA00;">&#40;</span>e<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#123;</span>
      e.preventDefault<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
      dropZone<span style="color: #6666ff;">.innerHTML</span> <span style="color: #00AA00;">=</span> e<span style="color: #6666ff;">.dataTransfer</span>.getData<span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'text/html'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>      
    <span style="color: #00AA00;">&#125;</span><span style="color: #00AA00;">,</span> false<span style="color: #00AA00;">&#41;</span></pre></div></div>

<p><strong>Summary</strong><br />
DnD spec is not completed &#038; it is also painful to develop a cross browser DnD solution with pure API now.</p>
<p><strong>Resources</strong><br />
<a href="http://www.html5rocks.com/en/tutorials/dnd/basics/" title="HTML5Rocks" target="_blank">Native HTML5 Drag and Drop &#8211; HTML5 Rocks</a><br />
<a href="http://playground.html5rocks.com/#drag_and_drop" target="_blank">Drag and drop html play ground</a><br />
<a href="https://developer.mozilla.org/En/DragDrop/Drag_and_Drop" target="_blank">Drag and Drop Mozilla MDN</a><br />
<a href="http://www.useragentman.com/blog/2010/01/10/cross-browser-html5-drag-and-drop/" target="_blank">Article on useragentman.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/css/weight-scale-html5-drag-drop-css3-rotation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StyleDocco &#8211; Create generated style guide and documentation for your web project</title>
		<link>http://www.decodize.com/css/styledocco-create-generated-style-guide-documentation-web-project/</link>
		<comments>http://www.decodize.com/css/styledocco-create-generated-style-guide-documentation-web-project/#comments</comments>
		<pubDate>Wed, 14 Mar 2012 13:17:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[styledocco]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=209</guid>
		<description><![CDATA[StyleDocco is a style guide and documentation generator. It parse CSS comments in your stylesheet and creates style guide based on the comments. Its a nodejs package and can install using npm install. Example style document generated using styledocco &#8211; &#8230; <a href="http://www.decodize.com/css/styledocco-create-generated-style-guide-documentation-web-project/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="Styledocco - style guide documents generator" href="http://jacobrask.github.com/styledocco/" target="_blank">StyleDocco </a>is a style guide and documentation generator. It parse CSS comments in your stylesheet and creates style guide based on the comments. Its a nodejs package and can install using <code>npm install</code>.</p>
<p>Example style document generated using styledocco &#8211; <a href="http://jacobrask.github.com/styledocco/examples/bootstrap/docs/index.html" title="Twitter bootstrap" target="_blank">twitter bootstrap</a></p>
<p><strong>Nodejs</strong></p>
<p>It is JavaScript running on server using google&#8217;s V8 JavaScript engine. Download latest node installer (win/mac/source code) form <a href="http://nodejs.org/">http://nodejs.org/</a> &amp; install it. </p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/nodejs.jpg" rel="lightbox"><img class="size-medium wp-image-213" title="nodejs" src="http://www.decodize.com/wp-content/uploads/2012/03/nodejs-300x266.jpg" alt="" width="300" height="266" /></a><br />
<span id="more-209"></span></p>
<p style="clear:both;">After installation open command prompt and type &#8220;node -v&#8221;. You will get the node version number.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/node-version.jpg" rel="lightbox"><img src="http://www.decodize.com/wp-content/uploads/2012/03/node-version-300x195.jpg" alt="" title="node-version" width="300" height="195" class="alignnone size-medium wp-image-225" /></a></p>
<p>After nodejs installation, install StyleDocco via npm (Node package manager). In windows open command prompt/mac terminal  &amp; type.<br />
<code>npm install -g styledocco</code>. In mac you have to type <code> sudo npm install -g styledocco </code>.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-install.jpg" rel="lightbox"><img src="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-install-300x219.jpg" alt="" title="styledocco-install" width="300" height="219" class="alignnone size-medium wp-image-214" /></a><br />
It will install in few minute depending upon your connection speed.</p>
<p><strong>Preparing stylesheet for documentation</strong></p>
<p>Styledocco uses <a href="https://github.com/chjj/marked" title="Markdown parser &#038; compiler" target="_blank">marked </a>to parse &amp; generate HTML. First we will check a simple stylesheet (example from <a href="https://github.com/jacobrask/styledocco/blob/master/README.md" title="Styledocco" target="_blank">author</a>).</p>
<pre>/* Provides extra visual weight and identifies the primary action in a set of buttons <br/> ``` &lt;button&gt;Primary&lt;/button&gt; ``` */ <br/>.btn.primary { background: blue; color: white; }</pre>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/readme-style-content.jpg" rel="lightbox"><img src="http://www.decodize.com/wp-content/uploads/2012/03/readme-style-content-300x219.jpg" alt="" title="readme-style-content" width="300" height="219" class="alignnone size-medium wp-image-216" /></a></p>
<p>Save the css on your site folder.  Now need a readme.md file. Create a text file and rename it to readme.md as save it on the same folder. In read me file you can use markdown to show the details about the style sheet. This readme will be the landing page of your style guide. Readme.md is required otherwise styledocco will throw an error.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/readme-style.jpg" rel="lightbox[209]"><img src="http://www.decodize.com/wp-content/uploads/2012/03/readme-style-300x219.jpg" alt="" title="readme-style" width="300" height="219" class="alignnone size-medium wp-image-218" /></a></p>
<p><strong>Style guide creation</strong></p>
<p>Syntax</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">styledocco <span style="color: #00AA00;">&#91;</span>options<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#91;</span>INPUT<span style="color: #00AA00;">&#93;</span></pre></div></div>

<p><em>Options</em><br />
&#8211;name, -n Name of the project (required)<br />
&#8211;out, -o Output directory (default: &#8220;docs&#8221;)<br />
&#8211;tmpl Directory for custom docs.jade template (optional)<br />
&#8211;overwrite Overwrite existing files (docs.css) in target directory.</p>
<p>Open command prompt and type.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">styledocco -n styleguide style.css</pre></div></div>

<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-create.jpg" rel="lightbox[209]"><img src="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-create-300x219.jpg" alt="" title="styledocco-create" width="300" height="219" class="alignnone size-medium wp-image-219" /></a></p>
<p>Styledocco will parse all comment in the document &amp; create style guide based on the comments provided in your css file. Styledocco uses <a href="http://daringfireball.net/projects/markdown/syntax" title="Markdown syntax " target="_blank">markdown syntax.</a></p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-output.jpg" rel="lightbox[209]"><img src="http://www.decodize.com/wp-content/uploads/2012/03/styledocco-output-300x219.jpg" alt="" title="styledocco-output" width="300" height="219" class="alignnone size-medium wp-image-220" /></a></p>
<p>Your style document will create inside docs folder. If you want a different directory to store output files use -o in your styledocco create command (<code>styledocco -n styleguide -o c:\styleguide style.css</code>). Open index.html form docs folder and you can see a botton and its style description.
<p>Styledocco is also capable of parsing LESS, SASS &amp; SCSS files and can generate style documents. Twitter <a href="http://jacobrask.github.com/styledocco/examples/bootstrap/docs/less/buttons.html" title="Twitter bootstrap with styledocco" target="_blank">bootstrap style guide</a> is an example.</p>
<p>Use markdown syntax in your readme.md &amp; stylesheet files. First &amp; second level of heading will automatically split into sections. If you want to exclude a comment, that you wish not being parsed by Styledocco, add a few space in front of the comment.</p>
<p>Example -</p>
<pre>
/*This comment will parse by Styledocco*/

     /*No this is an internal style comment*/
</pre>
<p>Large web projects we can use style guide for future reference and  optimization.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/css/styledocco-create-generated-style-guide-documentation-web-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Roboto font in windows desktop</title>
		<link>http://www.decodize.com/general/adding-roboto-font-windows-desktop/</link>
		<comments>http://www.decodize.com/general/adding-roboto-font-windows-desktop/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 10:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[roboto]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=187</guid>
		<description><![CDATA[in this post I&#8217;ll show you how to replace system fonts in windows with Roboto. Roboto is crafted for requirements of UI &#38; high-resolution screens. Steps to install 1. Download the font from google android design center. Robot font 2. &#8230; <a href="http://www.decodize.com/general/adding-roboto-font-windows-desktop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>in this post I&#8217;ll show you how to replace system fonts in windows with Roboto. Roboto is crafted for requirements of UI &amp; high-resolution screens.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-font.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-193" title="roboto-font" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-font-225x300.jpg" alt="" width="225" height="300" /></a></p>
<h3>Steps to install</h3>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto.jpg" rel="lightbox"><img class="alignnone size-full wp-image-188" title="roboto" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto.jpg" alt="Roboto font windows" width="274" height="416" /></a></p>
<p><span id="more-187"></span></p>
<p>1. Download the font from google android design center.<br />
<a title="Roboto font " href="https://developer.android.com/design/style/typography.html#actionbar" target="_blank">Robot font</a></p>
<p>2. Install the font<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-font-install.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-194" title="roboto-font-install" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-font-install-300x172.jpg" alt="" width="300" height="172" /></a></p>
<p>3. Right click desktop &amp; select personalize<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-personalize.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-195" title="roboto-personalize" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-personalize-197x300.jpg" alt="" width="197" height="300" /></a></p>
<p>4. Select window color<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-personalize-windowColor.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-196" title="roboto-personalize-windowColor" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-personalize-windowColor-300x218.jpg" alt="" width="300" height="218" /></a></p>
<p>5. Select advanced appearance settings<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-window-color-appearancejpg.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-197" title="roboto-window-color-appearancejpg" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-window-color-appearancejpg-300x218.jpg" alt="" width="300" height="218" /></a></p>
<p>6. Select Item drop down &amp; Change font to Roboto for the following.<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-color-appearance.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-198" title="roboto-color-appearance" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-color-appearance-200x300.jpg" alt="" width="200" height="300" /></a></p>
<p>7. To change windows system font &#8211; type regedit on windows run. Goto<br />
HKEY_LOCAL_MACHINE &gt; Software &gt; Microsoft &gt; Windows NT &gt; CurrentVersion &gt; FontSubstitutes<br />
<a href="http://www.decodize.com/wp-content/uploads/2012/03/roboto-regedit.jpg" rel="lightbox"><img class="alignnone size-medium wp-image-199" title="roboto-regedit" src="http://www.decodize.com/wp-content/uploads/2012/03/roboto-regedit-300x195.jpg" alt="" width="300" height="195" /></a></p>
<p>8. Restart</p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/general/adding-roboto-font-windows-desktop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 :target pseudo-class &#8211; Pure CSS based tab, lightbox and notification</title>
		<link>http://www.decodize.com/css/css3-target-pseudo-class-pure-css-based-tab-lightbox-notification/</link>
		<comments>http://www.decodize.com/css/css3-target-pseudo-class-pure-css-based-tab-lightbox-notification/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 20:31:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=134</guid>
		<description><![CDATA[Check out the demos to know what we are going to achieve with pure CSS. Pure CSS tabPure CSS image lightboxPure CSS notification Basics of target Target is a css3 selector. You can select an element using fragment identifier &#38; &#8230; <a href="http://www.decodize.com/css/css3-target-pseudo-class-pure-css-based-tab-lightbox-notification/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/target.jpg" rel="lightbox[134]"><img class="alignnone size-full wp-image-140" title="target" src="http://www.decodize.com/wp-content/uploads/2012/03/target.jpg" alt="" width="592" height="192" /></a></p>
<p>Check out the demos to know what we are going to achieve with pure CSS.</p>
<div class="demo"><a title="pure css based tab" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/tab.html#tab1" target="_blank">Pure CSS tab</a><a title="Pure CSS based image gallery modal window" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/gallery.html#" target="_blank">Pure CSS image lightbox</a><a title="Pure css based notification" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/notification.html" target="_blank">Pure CSS notification</a></div>
<p><strong>Basics of target</strong><br />
Target is a css3 selector. You can select an element using fragment identifier &amp; id.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/target-identifier.jpg" rel="lightbox[134]"><img class="alignnone size-full wp-image-141" title="target-identifier" src="http://www.decodize.com/wp-content/uploads/2012/03/target-identifier.jpg" alt="" width="592" height="192" /></a></p>
<p><span id="more-134"></span></p>
<p>Clicking on a link with anchor identifier bring you to certain part of the page</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/target-site.jpg" rel="lightbox[134]"><img class="alignnone size-full wp-image-146" title="target-site" src="http://www.decodize.com/wp-content/uploads/2012/03/target-site.jpg" alt="" width="592" height="579" /></a></p>
<p>By using :target css3 selector we can select the element with same id &amp; can apply style.</p>
<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/target-diagram.jpg" rel="lightbox[134]"><img class="alignnone size-full wp-image-148" title="target-diagram" src="http://www.decodize.com/wp-content/uploads/2012/03/target-diagram.jpg" alt="" width="592" height="192" /></a></p>
<p>Using this we are going to create a tab, image gallery &amp; notification only using CSS. Following codes are bare minimum requirement to build each modules. Please refer each demo&#8217;s code for more styling &amp; animation.</p>
<p><strong>Pure CSS tab</strong></p>
<hr />
<p><span>html</span></p>
<ul class="tab">
<li><a href="#tab1">Tab1</a></li>
<li><a href="#tab2">Tab2</a></li>
<li><a href="#tab3">Tab3</a></li>
</ul>
<div id="tab1">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip</div>
<div id="tab2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip</div>
<div id="tab3">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam</div>
<p><span>css</span></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">.tab<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.tab</span> li<span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#c1c1c1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
div<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
div<span style="color: #3333ff;">:target</span><span style="color: #00AA00;">&#123;</span>
 <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span> ​</pre></div></div>

<p>This is the bare minimum code you need to create a CSS only <a title="Minimum CSS based tab" href="http://jsfiddle.net/UzRfj/">tab</a>. But we can take this further and can make a beautiful tab.</p>
<p><a title="pure css based tab" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/tab.html#tab1" target="_blank">Check out this demo.</a></p>
<p><strong>Pure CSS image gallery [lightbox]</strong></p>
<hr />
<p><span>HTML</span></p>
<div><a href="#flower"><img class="alignnone size-full wp-image-159" title="target-01" src="http://www.decodize.com/wp-content/uploads/2012/03/target-01.png" alt="" width="76" height="76" /></a> <a href="#squirrel"><img class="alignnone size-full wp-image-158" title="target-thumb-02" src="http://www.decodize.com/wp-content/uploads/2012/03/target-thumb-02.png" alt="" width="76" height="76" /></a></div>
<ul>
<li id="flower"><a href="#"><img class="alignnone size-medium wp-image-161" title="IMG_0251" src="http://www.decodize.com/wp-content/uploads/2012/03/IMG_0251-300x200.jpg" alt="" width="300" height="200" /></a></li>
<li id="squirrel"><a href="#"><img class="alignnone size-medium wp-image-160" title="IMG_8806" src="http://www.decodize.com/wp-content/uploads/2012/03/IMG_8806-300x200.jpg" alt="" width="300" height="200" /></a></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">​</pre></div></div>

<p><span>CSS</span></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">li<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span>rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span>.5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
li<span style="color: #3333ff;">:target</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span>inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">middle</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
li img<span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-100px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-150px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
​</pre></div></div>

<p>With few lines of HTML &amp; CSS we created a modal window for image gallery. Next we will do some animations &amp; beautification.</p>
<p><a title="Pure CSS based image gallery modal window" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/gallery.html#" target="_blank">Check the demo.</a></p>
<p><strong>Pure CSS notification</strong></p>
<hr />
<p><span>HTML</span></p>
<div id="wrap">I&#8217;m a pure css based notification bar. <a href="#">X</a></div>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;a class<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;btn&quot;</span> href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;#wrap&quot;</span><span style="color: #00AA00;">&gt;</span>Click here to <span style="color: #993333;">show</span> notification&lt;/a<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p><span>CSS</span></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrap</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrap</span><span style="color: #3333ff;">:target</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">20%</span><span style="color: #00AA00;">;</span>
	opacity<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The code displayed above is minimum required code to make a pure css notification. check out this full featured <a title="Pure css based notification" href="http://www.decodize.com/demos/CSS3-target-pseudo-class/notification.html" target="_blank">demo</a>.</p>
<p><strong>Browser support</strong></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th>Chrome <small> [18 win &amp; 17 mac]</small></th>
<th>Safari <small> [5.1.x win &amp; mac]</small></th>
<th>Firefox <small> [11 win &amp; 10.0.2 mac]</small></th>
<th>Opera <small> [11.61 win &amp; mac]</small></th>
<th>Internet Explorer</th>
</tr>
<tr>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No <small>(IE9 &amp; 10- Incomplete)</small></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/css/css3-target-pseudo-class-pure-css-based-tab-lightbox-notification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplest full fledged code editor using data:text/html</title>
		<link>http://www.decodize.com/css/simplest-full-fledged-code-editor-datatexthtml/</link>
		<comments>http://www.decodize.com/css/simplest-full-fledged-code-editor-datatexthtml/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 15:16:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=77</guid>
		<description><![CDATA[In one of Paul Irish&#8217;s presentation &#8220;The Primitives of the HTML5 Foundation&#8221;. He showed creating a simplest code editor using data uri [link]. Inspired from it, I created a small full fledged JavaScript code editor [code highlight &#038; line number] &#8230; <a href="http://www.decodize.com/css/simplest-full-fledged-code-editor-datatexthtml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.decodize.com/wp-content/uploads/2012/03/javascript-code-editor.jpg" rel="lightbox[77]"><img src="http://www.decodize.com/wp-content/uploads/2012/03/javascript-code-editor.jpg" alt="" title="javascript-code-editor" width="603" height="195" class="alignnone size-full wp-image-132" /></a><br />
In one of <a href="http://paulirish.com" title="Paul Irish" target="_blank">Paul Irish&#8217;s</a> presentation <a href="http://dl.dropbox.com/u/39519/talks/html5-foundation/index.html#1" title="The Primitives of the HTML5 Foundation" target="_blank">&#8220;The Primitives of the HTML5 Foundation&#8221;</a>. He showed creating a simplest code editor using data uri [<a href="http://dl.dropbox.com/u/39519/talks/html5-foundation/index.html#38" title="link" target="_blank">link</a>]. Inspired from it, I created a small full fledged JavaScript code editor [code highlight &#038; line number] using Code mirror 2 &#038; data uri. </p>
<p>Following is the code from the presentation. Paste the code in your browser's adress bar and convert it into a simple code editor. </p>
<p><span id="more-77"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"> data:text/html,&lt;pre contenteditable&gt;</pre></div></div>

<p>Following code create a full javascript code editor using <a href="http://codemirror.net/" title="code mirror 2" target="_blank">Code mirror 2</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  data:text/html,&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/lib/codemirror.css&quot;&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/lib/codemirror.js&quot;&gt;&lt;/script&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/mode/javascript/javascript.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/doc/docs.css&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}&lt;/style&gt;&lt;h1&gt;JavaScript code editor&lt;/h1&gt;&lt;textarea id=&quot;code&quot; name=&quot;code&quot;&gt;&lt;/textarea&gt;&lt;script&gt;var editor = CodeMirror.fromTextArea(document.getElementById(&quot;code&quot;), {lineNumbers: true,matchBrackets: true});&lt;/script&gt;</pre></div></div>

<p>Copy &#038; paste code in browser's address bar and it magically changes your browser in to a javascript code editor with syntax highlight &#038; line number. </p>
<p>Adding  following code will change browser in to a CSS editor.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">data:text/html,&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/lib/codemirror.css&quot;&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/lib/codemirror.js&quot;&gt;&lt;/script&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/mode/css/css.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/doc/docs.css&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}&lt;/style&gt;&lt;textarea id=&quot;code&quot; name=&quot;code&quot;&gt;&lt;/textarea&gt;&lt;script&gt;var editor = CodeMirror.fromTextArea(document.getElementById(&quot;code&quot;), {lineNumbers: true,matchBrackets: true});&lt;/script&gt;</pre></div></div>

<p>Creating a bookmarklet let us access to code editor instantly. Drag and drop the following bookmarklet in to your bookmark region and click it to transform the browser into a javascript code editor.</p>
<p><a style="background:#eee; border:1px solid #ccc; padding:10px; border-radius:10px;" href='data:text/html,&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/lib/codemirror.css&quot;&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/lib/codemirror.js&quot;&gt;&lt;/script&gt;&lt;script src=&quot;http://www.decodize.com/codemirror/mode/javascript/javascript.js&quot;&gt;&lt;/script&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://www.decodize.com/codemirror/doc/docs.css&quot;&gt;&lt;style type=&quot;text/css&quot;&gt;.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}&lt;/style&gt;&lt;h1&gt;JavaScript code editor&lt;/h1&gt;&lt;textarea id=&quot;code&quot; name=&quot;code&quot;&gt;&lt;/textarea&gt;&lt;script&gt;var editor = CodeMirror.fromTextArea(document.getElementById(&quot;code&quot;), {lineNumbers: true,matchBrackets: true});&lt;/script&gt;' title="javascript code editor" target="_blank">JavaScript code editor</a></p>
<p>Since code mirror has so many supported modes: you can create code editors based on modes. Check out CodeMirror <a href="http://codemirror.net/" title="CodeMirror" target="_blank">CodeMirror</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/css/simplest-full-fledged-code-editor-datatexthtml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centering an element with percentage height &amp; width using CSS [Experiment]</title>
		<link>http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/</link>
		<comments>http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 11:49:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=50</guid>
		<description><![CDATA[Its just a quick post on a small issue I came across, when trying to center a div using absolute. There are couple of methods to make an element center. Quick way is to make it absolute &#038; give 50% &#8230; <a href="http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Its just a quick post on a small issue I came across, when trying to center a div using absolute. There are couple of methods to make an element center. Quick way is to make it absolute &#038; give 50% top &#038; left and negate margin top &#038; left with a value half of the width &#038; height of the element. </p>
<p><strong>Eg:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-100px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-100px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
&nbsp;
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>Above code will work in all browsers flawlessly. But consider the following css.</p>
<p><span id="more-50"></span></p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span><span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Changed to percentage width*/</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/*Changed to percentage height*/</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
&nbsp;
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>This code will fail in Firefox &#038; Opera. Other browsers it just works fine. There is a work around to make it center. Check the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*CSS*/</span>
<span style="color: #cc00cc;">#box</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#newBox</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">green</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;!-- HTML --<span style="color: #00AA00;">&gt;</span>
&lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;box&quot;</span><span style="color: #00AA00;">&gt;</span>
     &lt;div id<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;newBox&quot;</span><span style="color: #00AA00;">&gt;</span>
      &lt;/div<span style="color: #00AA00;">&gt;</span>
&lt;/div<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p>This code will center the newBox in all browsers. Responsive centering. Automatically adjust with container width.</p>
<p><a href="http://jsfiddle.net/cEDXx/12/" title="http://jsfiddle.net/cEDXx/12/">Check it on jsFddle</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/css/centering-an-element-with-percentage-height-width-using-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World!!</title>
		<link>http://www.decodize.com/general/world-2/</link>
		<comments>http://www.decodize.com/general/world-2/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 19:56:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.decodize.com/?p=37</guid>
		<description><![CDATA[After a long time I&#8217;m again starting my blog. This theme is Splendio 1.1 developed by DesignDisease (Elena &#038; Vlad Scanteie). I have customized it a bit. To know about me check here.]]></description>
			<content:encoded><![CDATA[<p>After a long time I&#8217;m again starting my blog. This theme is Splendio 1.1 developed by DesignDisease (Elena &#038; Vlad Scanteie). I have customized it a bit. To know about me check <a href="http://www.decodize.com/about/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.decodize.com/general/world-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

