<?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>Dave PC Guy &#187; Tutorials</title>
	<atom:link href="http://www.davepcguy.com/archive/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davepcguy.com</link>
	<description>Computers and Technology</description>
	<lastBuildDate>Fri, 10 Sep 2010 15:43:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How to learn another Programming Language</title>
		<link>http://www.davepcguy.com/archive/how-to-learn-another-programming-language/</link>
		<comments>http://www.davepcguy.com/archive/how-to-learn-another-programming-language/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 22:17:56 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/archive/how-to-learn-another-programming-language/</guid>
		<description><![CDATA[For the past few months, I have been struggling with trying to learn how to program in Javascript, one of the easiest languages one can learn (besides C, I suppose). I know to program in PHP pretty well, I got the whole concept down, and I’ve made plenty of sites to say that I’m experienced.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=javascript,programming,tutorial" height="61" width="50" /><br />
			</a>
		</div>
<p>For the past few months, I have been struggling with trying to learn how to program in Javascript, one of the easiest languages one can learn (besides C, I suppose). I know to program in PHP pretty well, I got the whole concept down, and I’ve made plenty of sites to say that I’m experienced. I can work with MySQL, and I can do plenty of other things. However, Javascript has been giving me a headache, that is, until recently.</p>
<p>I tried to work through the language the same way I did with PHP. I watched a few in-depth videos, I tried to do some tutorials on <a title="good-tutorials" href="http://www.good-tutorials.com" target="_blank">good-tutorials</a>, etc etc. But that did not work. However, I found a great way to get started with the language. I call this the “crash course method”.</p>
<h3>Crash Course Method</h3>
<p><span id="more-1383"></span></p>
<p>Here is a summary of my crash-course method:</p>
<ol>
<li>go on a tutorial site, one that goes from the beginning to the end with Javascript, such as <a title="w3 schools" href="http://www.w3schools.com" target="_blank">w3schools</a>. </li>
<li>look at the topics and write them down real quick like so ( – statements, – comments, – variables) </li>
<li>for each topic, make a little program to demonstrate the topic, here is an example for&#160; a <strong>for</strong> loop and <strong>comments:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:db8662d8-01da-4988-aa0b-57ab2e76350f" class="wlWriterEditableSmartContent">
<pre class="brush: html;">&lt;html&gt;
&lt;body&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
	document.write("Start for loop" + "&lt;br /&gt;");
// single line comment
	for (i = 0; i &lt;=5; i++)
	{
	document.write(i + "&lt;br /&gt;");
	}
/*
block comment
*/
	document.write ("For loop ends");
//--&gt;
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<p>    </strong></li>
<li>Don’t focus on the details of javascript, or the tutorials, each programming language works almost the same way (variables, loops, functions etc) so, simply see how javascript works and relate it to your language. For example, in PHP I used the <strong>echo </strong>function to print out text, javascript uses <strong>document.write()</strong> with the text between the parenthesis. In PHP, each variable has a dollar sign in front of it, in javascript, that is not the case. Do print out a variable, simply don’t use quotation marks. Make notes of these details, that’ll come in handy</li>
<li>Have fun! Make little programs, pointless programs that could be made without the use of javascript. Simply, get used to writing the code, don’t find a way around it, tackle the project with javascript</li>
</ol>
<p>The idea of a crash-course is not to focus on the details, and simply write code as much as possible. That helps the most, I found that out with PHP, and I’m starting to find this out with javascript as well.&#160; </p>
<ol></ol>
<p>Also, note that all programming languages work on a similar concept. Just because it looks unfamiliar, does not mean it does not follow the standard principles you’re used to.</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language&amp;bodytext=For%20the%20past%20few%20months%2C%20I%20have%20been%20struggling%20with%20trying%20to%20learn%20how%20to%20program%20in%20Javascript%2C%20one%20of%20the%20easiest%20languages%20one%20can%20learn%20%28besides%20C%2C%20I%20suppose%29.%20I%20know%20to%20program%20in%20PHP%20pretty%20well%2C%20I%20got%20the%20whole%20concept%20down%2C%20and%20I%E2%80%99ve%20made%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language&amp;notes=For%20the%20past%20few%20months%2C%20I%20have%20been%20struggling%20with%20trying%20to%20learn%20how%20to%20program%20in%20Javascript%2C%20one%20of%20the%20easiest%20languages%20one%20can%20learn%20%28besides%20C%2C%20I%20suppose%29.%20I%20know%20to%20program%20in%20PHP%20pretty%20well%2C%20I%20got%20the%20whole%20concept%20down%2C%20and%20I%E2%80%99ve%20made%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;t=How%20to%20learn%20another%20Programming%20Language" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language&amp;annotation=For%20the%20past%20few%20months%2C%20I%20have%20been%20struggling%20with%20trying%20to%20learn%20how%20to%20program%20in%20Javascript%2C%20one%20of%20the%20easiest%20languages%20one%20can%20learn%20%28besides%20C%2C%20I%20suppose%29.%20I%20know%20to%20program%20in%20PHP%20pretty%20well%2C%20I%20got%20the%20whole%20concept%20down%2C%20and%20I%E2%80%99ve%20made%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=For%20the%20past%20few%20months%2C%20I%20have%20been%20struggling%20with%20trying%20to%20learn%20how%20to%20program%20in%20Javascript%2C%20one%20of%20the%20easiest%20languages%20one%20can%20learn%20%28besides%20C%2C%20I%20suppose%29.%20I%20know%20to%20program%20in%20PHP%20pretty%20well%2C%20I%20got%20the%20whole%20concept%20down%2C%20and%20I%E2%80%99ve%20made%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;t=How%20to%20learn%20another%20Programming%20Language&amp;s=For%20the%20past%20few%20months%2C%20I%20have%20been%20struggling%20with%20trying%20to%20learn%20how%20to%20program%20in%20Javascript%2C%20one%20of%20the%20easiest%20languages%20one%20can%20learn%20%28besides%20C%2C%20I%20suppose%29.%20I%20know%20to%20program%20in%20PHP%20pretty%20well%2C%20I%20got%20the%20whole%20concept%20down%2C%20and%20I%E2%80%99ve%20made%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=How%20to%20learn%20another%20Programming%20Language%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=How%20to%20learn%20another%20Programming%20Language&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=How%20to%20learn%20another%20Programming%20Language&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fhow-to-learn-another-programming-language%2F&amp;title=How%20to%20learn%20another%20Programming%20Language" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/how-to-learn-another-programming-language/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Just a little stupid Javascript App</title>
		<link>http://www.davepcguy.com/archive/just-a-little-stupid-javascript-app/</link>
		<comments>http://www.davepcguy.com/archive/just-a-little-stupid-javascript-app/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 18:56:37 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1161</guid>
		<description><![CDATA[Remember how I promised I would learn Javascript so many times in the past? Well, I finally got around to learning some of the basics. And just like I did with PHP when I was learning it, I decided to create a simple application. I could not come up with a good idea so my]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=functions,javascript,lesson,tutorial" height="61" width="50" /><br />
			</a>
		</div>
<p>Remember how I promised I would learn Javascript so many times in the past? Well, I finally got around to learning some of the basics. And just like <a title="PHP poem" href="http://www.davepcguy.com/archive/simple-fun-with-php/">I did with PHP</a> when I was<a title="age tester" href="http://test.davepcguy.com/scripts/agetester/final.php"> learning it</a>, I decided to create a simple application. I could not come up with a good idea so my friend suggested one and within a couple of hours I finished it.</p>
<p>Here is <a title="Tea Cup" href="http://perfectlifetoday.com/teacup/">the demo</a>. I received some positive feedback from a lot of people so I thought I&#8217;d show how I, first of all, made it and how it helped me learn Javascript.<br />
<span id="more-1161"></span><br />
</p>
<h3>The Concept</h3>
<p>Okay, the concept was to create a site wherein one would receive advice to a question with a general advice quote or whatever else. Basically, a sentence or two that would guide the user. It works in a similar way as one of my older projects <a title="Only A Quote" href="http://www.davepcguy.com/archive/only-a-quote/">Only A Quote</a>, except this is pure javascript, no databases, and no php at all.</p>
<p>The idea is to set up variables, actually strings, that contain the quotes. One string = one quote. And then access these strings randomly. The access has to be inside the HTML (ie. no refreshing) and I want the text to fade out and fade back in with the advice quote.</p>
<p>Another thing I wanted to do was to have the answer appear in a teacup, etc. I&#8217;ll explain some of the basic CSS to do that, and same with how to create the cup in photoshop (I hate doing in-depth photoshop tutorials)</p>
<h3>Variables</h3>
<p>Believe it or not, I stored all of the quotes in a single variable, a single array actually. Here is how you go about it:</p>
<pre class="brush: jscript;">
var answer = new Array();

answer[0] = &quot;Never miss an opportunity to make others happy, even if you have to leave them alone in order to do it.&quot;;

answer[1] = &quot;You can tell more about a person by what he says about others than you can by what others say about him. &quot;;

answer[2] = &quot;Seek freedom and become captive of your desires.  Seek discipline and find your liberty.&quot;;
</pre>
<p>You can add as many answers as you wish, the only thing you have to do is follow the format: answer[next number] = &#8220;Answer text&#8221;;</p>
<p>Also, to initialize a variable just add the &#8220;var&#8221; in front of the variable name, an equal sign and the variable contents. Since this is an array I defined variable as an array by adding &#8220;new Array()&#8221;.</p>
<h3>Text and the Form</h3>
<p>The next thing we have to do is create the text field we want to dynamically change and the form to initialize several functions that will change the text, and do the fading.</p>
<p>This is the easiest part:</p>
<pre class="brush: xml;">
&lt;p id=&quot;Ans&quot;&gt;
What's your cup of tea?
&lt;/p&gt;
&lt;div id=&quot;form&quot;&gt;
&lt;form name=&quot;frm&quot;&gt;
&lt;input type=&quot;button&quot; value=&quot;Answer&quot; onclick=&quot;TextStuff()&quot; id=&quot;button&quot;/&gt;
&lt;/form&gt;
</pre>
<p>The paragraph Id-ed &#8220;Ans&#8221; is the place where the answer will appear. I created a form with an &#8220;onclick&#8221; event that points to the &#8220;TextStuff()&#8221; function. You can use basically anything for the onclick button. A div with an onclick, a textfield, anything at all but a button is rather convenient so I used that. You don&#8217;t have to Id anything other than the paragraph.</p>
<h3>Functions</h3>
<p>Next, let&#8217;s create a function that will change the text. I&#8217;m going to call it &#8220;message()&#8221;.</p>
<pre class="brush: jscript;">
function message() {
var ArrayLength = answer.length;
var r=Math.floor(Math.random()*ArrayLength);
document.getElementById('Ans').innerHTML = answer[r];

}
</pre>
<p>Let me explain this.First, I created a new variable that will get the number of array elements in my array. You can use the &#8220;.length&#8221; on any variable. For a string, the return value will be the number of characters. For an array, it will get the number of elements. The next variable &#8220;r&#8221; creates a random number with &#8220;Math.floor(Math.random()*number)&#8221;, you can replace &#8220;number&#8221; with any number that will be the ceiling for the random integer. For example, if you put 5 there, the random number will be between 0 and 5. By using putting &#8220;ArrayLength&#8221; there, you won&#8217;t have to keep changing this value if you add new quotes.</p>
<p>The last part basically means &#8220;in this <strong>document getElementById </strong>called <strong>(&#8216;Ans&#8217;)</strong> and do <strong>innerHTML</strong> so that <strong>answer[r]</strong> is the new value for the element with the &#8216;Ans&#8217; Id&#8221;. This will change the text within the paragraph Id-ed Ans.</p>
<p><strong>The Fade Function</strong></p>
<p>The next big thing I tackled was fading the text in and out. The problem here is is that I could not find a regular javascript function that could do this and I&#8217;m not skilled enough to figure it out myself. I took a shortcut and used JQuery.</p>
<pre class="brush: jscript;">
&lt;script src=&quot;http://code.jquery.com/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Put that in your header to include the latest JQuery version.<br />
Next, we will use the <strong>fadeIn </strong>and <strong>fadeOut</strong> JQuery functions. First, did you notice how the previous function I created is called &#8220;message()&#8221; while the onclick function is called &#8220;TextStuff()&#8221;? Well, here is where we create our &#8220;TextStuff()&#8221; function.</p>
<pre class="brush: jscript;">
function TextStuff() {
$(&quot;p&quot;).fadeOut(&quot;slow&quot;);
var t=setTimeout(&quot;message()&quot;, 2000);
}
</pre>
<p>Okay, first of all. JQuery functions do not work the same as regular javascript functions because JQuery is a framework and it has its own rules. Let me explain how this particular instance works. &#8220;$(&#8220;<strong>element</strong>&#8220;).fadeOut(<strong>speed, function to call</strong>);&#8221; I used the &#8220;p&#8221; (paragraph) element but you can use any other, even an #id. There are several speed settings such as &#8220;slow&#8221;, &#8220;fast&#8221;, or you can just put milliseconds there.</p>
<p>Second, I set the &#8220;message()&#8221; function to execute 2000 milliseconds (2 seconds) after the text fades out. the <strong>setTimeout</strong> function does this latent execution. You can replace the 2000 with any number you want.</p>
<p>Next I added a <strong>fadeIn</strong> function into the <strong>message()</strong> function.</p>
<pre class="brush: jscript;">
$(&quot;p&quot;).fadeIn(&quot;slow&quot;);
</pre>
<p>Just put this at beginning of the function before the ArrayLength variable.</p>
<h3>Where to put all this stuff</h3>
<p>This is the easy part. Put the functions in the header along with the call to the JQuery script. You can put the variable there as well or you can create a <strong>.js</strong> file with all the answers and call onto that like so:</p>
<pre class="brush: jscript;">
&lt;script src=&quot;answers.js&quot;&gt;&lt;/script&gt;
</pre>
<p>Don&#8217;t use the &lt;script type=&#8221;text/javascript&#8221;&gt; for the external file, just for the internal javascript calls. Put the form and the changing paragraph wherever you wish to inside your site. If you have any questions, go ahead and ask or just refer to the <a title="Tea Cup" href="http://perfectlifetoday.com/teacup/">demo</a> source file.</p>
<h3>The CSS and Photoshop Stuff</h3>
<p>This is pretty straight forward. I created several circles, one smaller than the other with a white fill. I used a single black-to-white gradient for each of those circles and added brightness and lowered contrast to create a smooth, light gradient. Next, I added some blending options. Notably, another low-opacity gradient for secondary shadows. I also used an &#8220;inner glow&#8221; set to multiply with a black color coming from the edge or the center (where it works better) with a 1 or 2px solid white stroke. This works the same way for the coffee, except I used a light brown to black gradient. The highlight is just a part of a circle with light opacity again.</p>
<p>I created the rest (the spoon, the teabag) the same way. The CSS is straightforward. I created a wide div to accommodate the cup and the other parts. Used a lot of padding from the top on another div that holds the answers. Under that, another div hosts the &#8220;answer&#8221; button and other stuff.<br />
That&#8217;s about it! I hope you enjoyed my short basic tutorial!<br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App&amp;bodytext=Remember%20how%20I%20promised%20I%20would%20learn%20Javascript%20so%20many%20times%20in%20the%20past%3F%20Well%2C%20I%20finally%20got%20around%20to%20learning%20some%20of%20the%20basics.%20And%20just%20like%20I%20did%20with%20PHP%20when%20I%20was%20learning%20it%2C%20I%20decided%20to%20create%20a%20simple%20application.%20I%20could%20not%20come%20up%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App&amp;notes=Remember%20how%20I%20promised%20I%20would%20learn%20Javascript%20so%20many%20times%20in%20the%20past%3F%20Well%2C%20I%20finally%20got%20around%20to%20learning%20some%20of%20the%20basics.%20And%20just%20like%20I%20did%20with%20PHP%20when%20I%20was%20learning%20it%2C%20I%20decided%20to%20create%20a%20simple%20application.%20I%20could%20not%20come%20up%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;t=Just%20a%20little%20stupid%20Javascript%20App" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App&amp;annotation=Remember%20how%20I%20promised%20I%20would%20learn%20Javascript%20so%20many%20times%20in%20the%20past%3F%20Well%2C%20I%20finally%20got%20around%20to%20learning%20some%20of%20the%20basics.%20And%20just%20like%20I%20did%20with%20PHP%20when%20I%20was%20learning%20it%2C%20I%20decided%20to%20create%20a%20simple%20application.%20I%20could%20not%20come%20up%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Remember%20how%20I%20promised%20I%20would%20learn%20Javascript%20so%20many%20times%20in%20the%20past%3F%20Well%2C%20I%20finally%20got%20around%20to%20learning%20some%20of%20the%20basics.%20And%20just%20like%20I%20did%20with%20PHP%20when%20I%20was%20learning%20it%2C%20I%20decided%20to%20create%20a%20simple%20application.%20I%20could%20not%20come%20up%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;t=Just%20a%20little%20stupid%20Javascript%20App&amp;s=Remember%20how%20I%20promised%20I%20would%20learn%20Javascript%20so%20many%20times%20in%20the%20past%3F%20Well%2C%20I%20finally%20got%20around%20to%20learning%20some%20of%20the%20basics.%20And%20just%20like%20I%20did%20with%20PHP%20when%20I%20was%20learning%20it%2C%20I%20decided%20to%20create%20a%20simple%20application.%20I%20could%20not%20come%20up%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Just%20a%20little%20stupid%20Javascript%20App%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Just%20a%20little%20stupid%20Javascript%20App&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Just%20a%20little%20stupid%20Javascript%20App&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fjust-a-little-stupid-javascript-app%2F&amp;title=Just%20a%20little%20stupid%20Javascript%20App" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/just-a-little-stupid-javascript-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobile Websites (tips)</title>
		<link>http://www.davepcguy.com/archive/mobile-websites-tips/</link>
		<comments>http://www.davepcguy.com/archive/mobile-websites-tips/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 23:28:37 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1051</guid>
		<description><![CDATA[I&#8217;ve recently started working on some mobile websites. You&#8217;ll notice that davepcguy.com has its own mobile alternative as do some other sites. Mobile devices are growing in number and gone are those days when internet was viewed only on the computer screen. WAP is not even used either so that old school coding is gone]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=css,Design,HTML%2FCSS,mobile,php,webpage,website" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;ve recently started working on some mobile websites. You&#8217;ll notice that davepcguy.com has its own mobile alternative as do some other sites. Mobile devices are growing in number and gone are those days when internet was viewed only on the computer screen. WAP is not even used either so that old school coding is gone too.</p>
<p>These days, almost everyone has an iPhone or a BlackBerry, or a Palm device. Some of us even have other devices like PSPs, tablets, and others that require quite a bit different formatting. Here&#8217;s how to go about making your mobile website.<br />
<span id="more-1051"></span><br />
</p>
<h1>Step 1 &#8211; The Vision</h1>
<p>First, you gotta have a vision of what you want. The best way to get a good vision is by picking up your phone and browsing the internet, looking through some popular websites such as <a title="Youtube" href="http://www.youtube.com">youtube</a>, <a title="Flickr" href="http://www.flickr.com">flickr</a>, <a title="Facebook" href="http://www.facebook.com">facebook</a>, <a title="Myspace" href="http://www.myspace.com">myspace</a>, and other sites that you know get a lot of traffic and are likely to have their own mobile version.</p>
<p>I recently saw a really nice blog <a title="Woorkup" href="http://woorkup.com/2010/01/10/best-practices-to-develop-perfect-websites-for-iphone-and-mobile-devices/">post</a> detailing some of the nicer mobile sites. The theme there is common:</p>
<p><a rel="attachment wp-att-1052" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile1/"><img class="aligncenter size-full wp-image-1052" title="mobile1" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile1.png" alt="" width="380" height="448" /></a>Everything is single column. There are no side-bars, there are no fancy tabs. Everything is in a single column. Think of it as a letter. There are no columns in a letter, you have a header, the body, and the footer.</p>
<ol>
<li>Header: Generally, you&#8217;ll use the header of the page to announce the website&#8217;s name and to show menu links. You may also place a commercial in this area (Google Adsense uses commercials). Here&#8217;s what I used on my <a title="Mobile Only A Quote" href="http://m.onlyaquote.com">Only A Quote</a> mobile site: <a rel="attachment wp-att-1053" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile2/"><img class="aligncenter size-full wp-image-1053" title="mobile2" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile2.png" alt="" width="298" height="62" /></a>It&#8217;s a simple banner that effectively tells the user what&#8217;s going on.</li>
<li>Body: This is pretty self-explanatory, you put the meet of your site here. Try to use well organized information. Don&#8217;t just slap stuff there. Mobile users are more likely to leave your site than regular computer users. Also, keep the graphics swift! Not too much.</li>
<li>Footer: Use the footer for copyright info and other blah blah stuff but don&#8217;t over do it! I know huge footers are fashionable but not for mobile users!</li>
</ol>
<p>Keep it all simple!</p>
<h1>Step 2 &#8211; Design</h1>
<p>Here are a few tools that will help you with your design:</p>
<ul>
<li><a title="iPhone tester" href="http://iphonetester.com/">iPhone tester</a></li>
<li><a title="mobile emulators" href="http://mobiforge.com/emulators/page/mobile-emulators">Mobile Emulators</a></li>
<li>more <a title="mobile emulators" href="http://www.klauskomenda.com/archives/2008/03/17/testing-on-mobile-devices-using-emulators/">mobile emulators</a></li>
</ul>
<p>Keep in mind that different phones will render your page differently so try to make it as simple as possible. To catch the widest possible audience, focus on the big three: iPhones, BlackBerries, and Palm phones. Samsung and Nokias are common too, especially outside of the US but BBs and iPhones capture most of the market. Android is coming up too, so watch out for them too.</p>
<p>A few simple rules:</p>
<ul>
<li>Keep the site less then 400px wide.</li>
<li>Cross-browsing is a bitch on Computers, it&#8217;s worse on phones, render for Safari and Opera Mobile</li>
<li>Graphics should not exceed 20kbs</li>
<li>Keep the layout basic</li>
</ul>
<p>There are tons  more rules but those are the basics.</p>
<h1>Step 3 &#8211; Coding</h1>
<p>First of all, DON&#8217;T USE JAVASCRIPT! It works on a lot of phones, it&#8217;s gaining support, but it&#8217;s really bothersome (I know, I use my phone to browse the net a lot). There&#8217;s no need for it. Hover and other pretty stuff is useless too. Many phones don&#8217;t support it.</p>
<p>Use as little mark-up code as you can. If your original site has thirty divs, make it three in this one. There&#8217;s no need for all that on phones. If your CSS screws up, so will your divs.</p>
<p>Use the following doctype:</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//WAPFORUM//DTD XHTML Mobile 1.2//EN&quot;&quot;http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd&quot;&gt;
</pre>
<p>This will tell the browser that it&#8217;s meant for phones. It&#8217;ll help rendering and it&#8217;s the RIGHT thing to do haha. Once you start coding, again, keep in mind that your website should be the smallest possible.</p>
<p>Here are a couple of rules to keep in mind:</p>
<ol>
<li>Don&#8217;t use px/em sizes, do everything in percentages, you never know what kind of a phone the user will use.</li>
<li>Keep all files as small as possible.</li>
<li>If your .PNG graphics do not use transparency, convert them to JPGs with smaller quality</li>
<li>If you use .PNG graphics WITH transparency, consider remaking them into JPGs or GIFs (for transparency) if at all possible</li>
<li>Keep all graphics less than 400px wide. I suggest 350px tops.</li>
<li>Use &#8220;ALT&#8221; for images, some phones may not render the text and it&#8217;s standard .mobi rule</li>
<li>Try not to use tables or javascript</li>
<li>Don&#8217;t use external resources (ie pictures from other sites, scripts from other sites, etc)</li>
<li>Define sizes for images with the width = &#8220;&#8221; and height = &#8220;&#8221; html tags</li>
<li>NO POP UPS!</li>
</ol>
<p>That&#8217;s about it.</p>
<h1>Step 4 &#8211; Testing</h1>
<p>You&#8217;ll need to test your site, so use the resources mentioned in the emulator part. Use your phone as well!</p>
<p>Here&#8217;s another resource that will catch ALL of your mistakes:</p>
<p><a title="ready mobi" href="http://ready.mobi/">Ready.mobi</a></p>
<p>This site checks your markup, the size of your site, and many other features. It will tell you if you did something wrong and will usually tell you what you can fix on your site. It also features five different phone emulators on the spot. It also ranks the speed of your site. Here are my stats:</p>
<p><a rel="attachment wp-att-1054" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile3/"><img class="aligncenter size-medium wp-image-1054" title="mobile3" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile3-300x255.png" alt="" width="300" height="255" /></a>Oh yeah, that&#8217;s a bad rating. It&#8217;s mostly because of all the graphics on my site, the CSS involved and inter-linking on my blog. It happens but it does pretty well on my BlackBerry so try to look at your rating positively especially after you do your own tests. As you can see, it tells you the different speeds with GPRS, 3G, and Wi-fi.</p>
<h1>Step 5 &#8211; Implementation</h1>
<p>Let me save you a few hours of searching. In implementation, you&#8217;ll have to figure out how exactly you&#8217;re going to redirect your traffic to the mobile version whence they use their phones. It took some time for me to figure out but here are a few options:</p>
<ol>
<li><a title="detect mobile browsers" href="http://detectmobilebrowsers.mobi/">DetectMobileBrowsers</a> &#8211; This is almost a fullproof method of redirecting your traffic. The problem? You can&#8217;t use it unless your site is COMPLETELY non-profit. Nope, not even ads are allowed. If you want the commercial version, it will cost you $50 a year to use it</li>
<li><a title="Light Weight Device Detection" href="http://mobiforge.com/developing/story/lightweight-device-detection-php">LightWeight Device Detection</a> &#8211; This is probably one of the simplest scripts you&#8217;ll find and it works really well. It also doesn&#8217;t have any restrictions as far as I&#8217;m aware.</li>
<li><a title="Mobile Detect" href="http://www.jooria.com/scripts/Wireless-and-Mobile-156/Mobile-Detect-923/index.html">Mobile Detect</a> &#8211; This is a slightly more functional version of the above-mentioned Device Detection. They&#8217;re not related but work in a similar way</li>
</ol>
<p>Let&#8217;s move on to actually using these scripts. I haven&#8217;t used number one but I&#8217;ll tell you how you can incorporate number 2 and 3.</p>
<ol>
<li>Decide whether you want a separate site for the mobile version. I recommend creating a sub-domain such as m.onlyaquote.com (whence using sub-domains, remember that m.onlyaquote.com = onlyaquote.com/m )</li>
<li>If you did not create a separate sub-domain, you can place the whole thing in a loop but don&#8217;t forget to create a backdoor so that the user can switch between the desktop and mobile version.</li>
<li>Put all the script messy stuff into a separate file (so as not to clutter up your index.php file) except for the if/else statement found in number 2. If you&#8217;re using number 3, don&#8217;t worry about that at all.</li>
<li>Use <strong>include(script file ); </strong>to put the script back into your index.php file. Put all of your PHP before the &lt;html&gt; tag</li>
</ol>
<p>If you&#8217;re using Number 2, here&#8217;s what you do:</p>
<pre class="brush: php;">
include ('scriptfile.php');
if($mobile_browser&gt;0) {
   // do something
header( 'Location: mobilesite.com' ) ;
}
</pre>
<p>If you&#8217;re not using a different site do this:</p>
<pre class="brush: php;">
include('scriptfile.php');
if($mobile_browser&gt;0) {
 // place your mobile site here.
}
else {
   // place your desktop version here
}
</pre>
<p>You can also simply switch out CSS files with this method (make sure to put the loop inside the &lt;head&gt; tag then). I don&#8217;t suggest you use the default CSS method of switching styling according to the device (ie. &lt;link rel=&#8221;stylesheet&#8221; type=&#8221;text/css&#8221; href=&#8221;css/quotestyles.css&#8221; media=&#8221;handheld&#8221; /&gt;) because it doesn&#8217;t work that well and most devices will try to read BOTH stylesheets.</p>
<p>For number 3, again place the following loop before the &lt;html&gt; tag:</p>
<pre class="brush: php;">
include(&quot;Mobile_Detect.php&quot;);
$detect = new Mobile_Detect();
if ($detect-&gt;isMobile()) {
    // any mobile platform
header( 'Location: mobilesite.com' ) ;
}
</pre>
<p>With the number 3 method (ie. <a title="mobile detect" href="http://www.jooria.com/scripts/Wireless-and-Mobile-156/Mobile-Detect-923/index.html">Mobile Detect</a>) you can also specify which mobile device you want to do what. You can choose a separate site for an iPhone and Blackberry or separate CSS files. Well, whatever, you can do it all.</p>
<p>CAUTION: The detection system is NOT perfect. With newer phones, newer browsers, and newer software, the detection script may become obsolete. Be always on the look out for better versions!</p>
<h1>Conclusion</h1>
<p>That&#8217;s it, with these few tricks, you should be able to easily make your own mobile site. Here&#8217;s what mine looks like (I still have a TON of work to do!):</p>
<p><a rel="attachment wp-att-1055" href="http://www.davepcguy.com/archive/mobile-websites-tips/mobile4/"><img class="aligncenter size-medium wp-image-1055" title="mobile4" src="http://www.davepcguy.com/wp-content/uploads/2010/01/mobile4-228x300.png" alt="" width="228" height="300" /></a><br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;bodytext=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;notes=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;t=Mobile%20Websites%20%28tips%29" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;annotation=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;t=Mobile%20Websites%20%28tips%29&amp;s=I%27ve%20recently%20started%20working%20on%20some%20mobile%20websites.%20You%27ll%20notice%20that%20davepcguy.com%20has%20its%20own%20mobile%20alternative%20as%20do%20some%20other%20sites.%20Mobile%20devices%20are%20growing%20in%20number%20and%20gone%20are%20those%20days%20when%20internet%20was%20viewed%20only%20on%20the%20computer%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Mobile%20Websites%20%28tips%29%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Mobile%20Websites%20%28tips%29&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Mobile%20Websites%20%28tips%29&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fmobile-websites-tips%2F&amp;title=Mobile%20Websites%20%28tips%29" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/mobile-websites-tips/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Bit.ly API and adding URLs to your MySQL database</title>
		<link>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/</link>
		<comments>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 22:16:10 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[url-shortener]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1011</guid>
		<description><![CDATA[In my last tutorial, I&#8217;ve touched on how to use the to.ly API and how to make automatic &#8220;Tweet it&#8221; buttons with a relevant message. Well, this can get problematic if with every page refresh, your server sends out a request to the to.ly server for a short link. Pretty soon, you&#8217;ll be getting &#8220;Too]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=API,internet,php,server,social+networking,url-shortener" height="61" width="50" /><br />
			</a>
		</div>
<p>In my last<a title="tweet this and URL shortening API" href="http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/"> tutorial</a>, I&#8217;ve touched on how to use the to.ly API and how to make automatic &#8220;Tweet it&#8221; buttons with a relevant message.<br />
Well, this can get problematic if with every page refresh, your server sends out a request to the to.ly server for a short link. Pretty soon, you&#8217;ll be getting &#8220;Too Many Connections&#8221; and you&#8217;re screwed. Just like I was, so here&#8217;s an idea. How about we store those links in a database&#8230;.automatically?</p>
<p>You see, it&#8217;s much easier to create a script that will request a shortlink, adds the link to the database, and then just call it up whenever you need it. It works perfectly well on my <a title="Only A Quote" href="http://www.onlyaquote.com">quote site</a>. Basically, whenever you create a website with get-requests, tons of pages, and all that. You can use the following script to make it all work, automatically (again).</p>
<ul>
<li><a href="#bitly">Bit.ly shortlink implementation</a></li>
<li><a href="#mysql">Adding URL Links to a MySQL database</a></li>
</ul>
<br />
<span id="more-1011"></span></p>
<h1><a name="bitly">Bit.ly</a></h1>
<p>Let&#8217;s get some bit.ly action going here. First, you need to create an account. Then you need to get the <a title="bitly API key" href="http://bit.ly/account/your_api_key">bit.ly API key</a><a rel="attachment wp-att-1012" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/bitly/"><img class="aligncenter size-medium wp-image-1012" title="bitly" src="http://www.davepcguy.com/wp-content/uploads/2009/12/bitly-300x200.png" alt="" width="300" height="200" /></a>Next, let&#8217;s look at a neat <a title="bitly php script" href="http://davidwalsh.name/bitly-php">script</a> I found and made a few changes to so you could simply use include() and have a ready function with all the right variables:</p>
<pre class="brush: php;">
// Variables
$bitlylogin = 'loginname';
$apikey = 'long series of numbers that make up your API key';

/* make a URL small */
function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
{
 //create the URL
 $bitly = 'http://api.bit.ly/shorten?version='.$version.'&amp;longUrl='.urlencode($url).'&amp;login='.$login.'&amp;apiKey='.$appkey.'&amp;format='.$format;

 //get the url
 //could also use cURL here
 $response = file_get_contents($bitly);

 //parse depending on desired format
 if(strtolower($format) == 'json')
 {
 $json = @json_decode($response,true);
 return $json['results'][$url]['shortUrl'];
 }
 else //xml
 {
 $xml = simplexml_load_string($response);
 return 'http://bit.ly/'.$xml-&gt;results-&gt;nodeKeyVal-&gt;hash;
 }
}
</pre>
<p>I like to set my function up like this so that I can always interchange values, and so that I will automatically have the right values stored in those two variables above ($bitlylogin and $apikey). You don&#8217;t need to do that. You could simply change the function definition like to include defaults:</p>
<pre class="brush: php;">
function make_bitly_url($url,$login = 'loginusername',$appkey = 'long api key',$format = 'xml',$version = '2.0.1')
</pre>
<p>Now as far as implementation of the script goes, it&#8217;s pretty simple:</p>
<pre class="brush: php;">
$url = &quot;Http://www.davepcguy.com&quot;;
$shorturl = make_bitly_url($url, $bitlylogin, $apikey);
echo $shorturl;
</pre>
<p>And you&#8217;ll get the short url echoed out. If you use the default value version you can simply do this:</p>
<pre class="brush: php;">
$url = &quot;http://www.davepcguy.com&quot;;
$shorturl = make_ibtly_url($url);
echo $shorturl;
</pre>
<p>You&#8217;re done. Easy enough, eh?</p>
<h1><a name="mysql">MySQL Database</a></h1>
<p>Believe it, or not. It&#8217;s actually rather tricky to add a URL into a database. You have to select the correct format in the table, decode and encode stuff. It&#8217;s pretty messy and I have not found a good tutorial online on how to do this.<br />
So here goes, let&#8217;s assume you use the method above to create short links. It&#8217;ll make life much easier, trust me.</p>
<p>First, let&#8217;s create a table in your database:</p>
<pre class="brush: php;">
//login variables
$host = 'localhost';
$user = 'username';
$pass = 'password';
$db = 'sample database';

//connect
$connection = mysql_connect($host, $user, $pass) or die ('Unable to connect!');

//database select
mysql_select_db($db) or die ('Unable to select database!');

//the right query
$query = &quot;CREATE TABLE sample_table
(
id int NOT NULL auto_increment primary key,
name varchar(50) NOT NULL,
email varchar(50) NOT NULL ,
message text NOT NULL,
url varchar(255) NOT NULL
)&quot;;

//executing query
$result = mysql_query($query) or die ('Error in Query');
</pre>
<p>Notice that I used a varchar(255) for the datatype. You could use varchar(55) or any other number. Every shortlink by bit.ly is 20 characters&#8230;max. The problem is when you add the information in your database so I recommend a good 255 characters.</p>
<p>Next, you have to make sure you know what you want out of the script. I made a script so that every time my website asked for a row of information, it would automatically add the URL (since I was a bit late with this idea, I had to find a way to add the information without having to recreate the whole database). Also, it&#8217;s a good practice to check if the data is present and in case it&#8217;s not, add it. Here&#8217;s what I did:</p>
<pre class="brush: php;">
//connect

$name = 'sample name';

//query for a particular row with the name
$query = 'SELECT * FROM sample_table WHERE name = $name'';

    // execute query
    $result = mysql_query($query) or die (&quot;Error in query: $query.&quot;.mysql_error());

//check if the url column has anything in it
if (empty($row[4])) {

//if it IS empty, let's make a shortlink
$url = make_bitly_url($permalink,$bitlylogin,$apikey,'xml');
//we have to encode the url. I'll explain that
$url = urlencode($url);
//make a query to update (don't forget the quotation marks!)
$query = 'UPDATE quotes SET url = &quot;'.$url.'&quot; WHERE name = '.$name.'';
//execute query
$urlresult = mysql_query($query) or die (&quot;Error in query: $query. &quot;.mysql_error());
//decode url for later use in the script
$url = urldecode($url);
}

//let's make an else statement in case the information IS present
else {
//let's decode that encoded url
$url = urldecode($row[4]);
}
</pre>
<p>Now you have the $url variable down! w00t. You can do a bunch of stuff with that. Like implement it in that <a title="Tweet this!" href="http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/">twitter button</a> I keep talking about. Check out my <a title="Only A Quote" href="http://www.onlyaquote.com">new site</a> too to see it in action.</p>
<p>Oh about that encoding and decoding. If you try to submit the $url without encoding it, you&#8217;ll get an error because the characters &#8220;/&#8221; and &#8220;:&#8221; and some of the other ones have a special meaning in SQL. Here&#8217;s what the encoded and decoded versions look like:</p>
<blockquote><p>normal: http://bit.ly/8oQBvB</p>
<p>encoded: http%3A%2F%2Fbit.ly%2F8oQBvB</p>
<p>decoded: http://bit.ly/8oQBvB</p></blockquote>
<p>As you can see, the encoded version uses the &#8220;%&#8221; characters (ascii) for the coding.</p>
<p>Don&#8217;t forget to encode and decode then!</p>
<p>I hope you enjoyed my tutorial <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;bodytext=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;notes=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;t=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;annotation=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;t=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;s=In%20my%20last%20tutorial%2C%20I%27ve%20touched%20on%20how%20to%20use%20the%20to.ly%20API%20and%20how%20to%20make%20automatic%20%22Tweet%20it%22%20buttons%20with%20a%20relevant%20message.%0D%0AWell%2C%20this%20can%20get%20problematic%20if%20with%20every%20page%20refresh%2C%20your%20server%20sends%20out%20a%20request%20to%20the%20to.ly%20server%20for%20a%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fbit-ly-api-and-adding-urls-to-your-mysql-database%2F&amp;title=Bit.ly%20API%20and%20adding%20URLs%20to%20your%20MySQL%20database" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>&#8220;Tweet This&#8221; and URL shortening API</title>
		<link>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/</link>
		<comments>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 23:00:26 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[PHP and Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[social networking]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[url-shortener]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=1004</guid>
		<description><![CDATA[Alright, you&#8217;ve all seen those CRAZY &#8220;Tweet This&#8221; buttons on so many websites, (mainly wordpress). You may have also noticed that some just send you to twitter and you have to manually input the twitter message. Well, how about we just make a button that will automate all this for us? I really do love]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=functions,php,server,social+networking,twitter,url-shortener" height="61" width="50" /><br />
			</a>
		</div>
<p>Alright, you&#8217;ve all seen those CRAZY &#8220;Tweet This&#8221; buttons on so many websites, (mainly wordpress). You may have also noticed that some just send you to twitter and you have to manually input the twitter message. Well, how about we just make a button that will automate all this for us?</p>
<p>I really do love it when I click on that button and twitter pops up with a pre-written message like &#8220;Check out this site : URL GOES HERE&#8221; or &#8220;Crazy CSS tutorial on backgrounds. Check it out: URL GOES HERE&#8221;, it makes it much easier for me to share my finds. Here&#8217;s a great <a title="Only A Quote" href="http://www.onlyaquote.com">demo</a>.</p>
<p>Okay, I&#8217;m working on a new website and it has various posts on it that I want the readers to be able to automatically share on twitter. I also want to include a backlink so that their twitter followers can visit the actual article. Basically, here&#8217;s a tutorial on shortening URLs using API and for creating a twitter button.</p>
<p><span id="more-1004"></span><br />
</p>
<h2>URL shortening</h2>
<p>As you may know, there are tons of <a title="comparing short links" href="http://www.davepcguy.com/archive/comparing-short-links/">URL shortening services</a>. Most, including<a title="bit.ly" href="http://www.bit.ly"> bit.ly</a> and<a title="tiny url " href="http://www.tinyurl.com"> tinyurl.com</a> support API services which basically means, you can use PHP (and AJAX) in order to use their services on another server. That&#8217;s BASICALLY what it means. I&#8217;m not a master of this. Bit.ly requires an account so I won&#8217;t be getting into that. I don&#8217;t want my account to be spammed with a ton of different links. But, if you want to keep track of how many people clicked and posted your link, you are more than welcome to read a tutorial on it <a title="bitly php api" href="http://davidwalsh.name/bitly-php">elsewhere</a>.</p>
<p>I&#8217;m not too big on tinyurl.com anymore because it requires way too many characters. And for twitter use, it&#8217;s basically useless so I browsed around and found <a title="to.ly shrinking URLs" href="http://to.ly">to.ly</a> which has really basic API info already <a title="to.ly api info" href="http://to.ly/api_info.php">posted</a>. Let me copy it real quick:</p>
<pre class="brush: php;">
function CompressURL($url) {

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, &quot;http://to.ly/api.php?longurl=&quot;.urlencode($url));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HEADER, 0);

  $shorturl = curl_exec ($ch);
  curl_close ($ch);

  return $shorturl;

}
</pre>
<p>Add this function to your function.php, if you use an external function list (use require() to add it to your site), or just add this function in your header on your site so that whenever you call upon it later, it will be at your disposal. Now, let&#8217;s get the URL of the site you&#8217;re on. Let&#8217;s say you have a dynamic page and don&#8217;t feel like manually writing each separate link. We can use the $_SERVER variable for that. A combination actually:</p>
<pre class="brush: php;">
echo &quot;http://&quot;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
</pre>
<p>This will echo out the whole URL, including any GET statements you may have entered. If you don&#8217;t want those statements, erase the last $_SERVER variable. Okay, so let&#8217;s put it all together to shorten the link using the previous function:</p>
<pre class="brush: php;">
$permalink = &quot;http://&quot;.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
$url = CompressURL (&quot;$permalink&quot;);
</pre>
<p>Now that we have the compressed URL, let&#8217;s move on to the tweet button.</p>
<h2>Tweet This Button!</h2>
<p>Well, go out and find some great twitter icon. Or make your own. It&#8217;s easy. You go into photoshop and make a 150 x 50 px rectangle and write twitter in it. That&#8217;s not what this tutorial is about.<br />
Twitter has an easy-to-use API (Is it even API?).</p>
<pre class="brush: xml;">
http://twitter.com/home?status= MESSAGE GOES HERE
</pre>
<p>So there goes the message. Very easy, no? Now, here lies the problem. What kind of message do you want? You could use different functions and variables that describe each page on your site. If you set them manually (in the META tag), use this instead so that the description is already stored for later use. In my <a title="Only A Quote" href="http://www.onlyaquote.com">newest site</a>, I used the actual content of the page (a quote) for the message:</p>
<pre class="brush: php;">
$description = &quot;An article about php scripting and creating a simple tweet this button.&quot;;
echo $description
</pre>
<p>Twitter has a character limit of one forty, right? We can take care of that too. &#8220;substr()&#8221; is a function that will allow you to cut up your description. It works like this: substr($string, begin cut, end cut). I use a 100 character cut off:</p>
<pre class="brush: php;">

$twittermsg = substr($description, 0, 100);

$twittermsg .= &quot;...more on&quot;.$url;
</pre>
<p>The message is complete. A hundred character message ending with &#8220;&#8230;more on URL&#8221;. Finally, the button and link:</p>
<pre class="brush: xml;">
&lt;a href=&quot;http://twitter.com/home?status=&lt;?php echo $twittermsg;?&gt;&quot; target=&quot;_blank&quot;&gt; &lt;img src=&quot;pictures/images/twitter_button.png&quot; title=&quot;Tweet it!&quot; onmouseover=&quot;this.src='pictures/images/twitter_button_hover.png'&quot;
onmouseout=&quot;this.src='pictures/images/twitter_button.png'&quot; /&gt;&lt;/a&gt;
</pre>
<p>The &#8220;onmouseover&#8221; and &#8220;onmouseout&#8221; are used for a nice hover effect (onmouseover will be the hoveved, and onmouseout is the non-hovered). Using CSS would be a literal pain because you&#8217;d have to create a clickable div or a span&#8230;display none. Well, just trust me, this is MUCH easier.</p>
<p>I hope you enjoyed this short tutorial!</p>
<p><strong>Check out my next <a title="Bit.ly API" href="http://www.davepcguy.com/archive/bit-ly-api-and-adding-urls-to-your-mysql-database/">tutorial</a> for bit.ly API! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong><br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;bodytext=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;notes=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;t=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;annotation=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;t=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;s=Alright%2C%20you%27ve%20all%20seen%20those%20CRAZY%20%22Tweet%20This%22%20buttons%20on%20so%20many%20websites%2C%20%28mainly%20wordpress%29.%20You%20may%20have%20also%20noticed%20that%20some%20just%20send%20you%20to%20twitter%20and%20you%20have%20to%20manually%20input%20the%20twitter%20message.%20Well%2C%20how%20about%20we%20just%20make%20a%20button%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%22Tweet%20This%22%20and%20URL%20shortening%20API%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=%22Tweet%20This%22%20and%20URL%20shortening%20API&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Ftweet-this-and-url-shortening-api%2F&amp;title=%22Tweet%20This%22%20and%20URL%20shortening%20API" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/tweet-this-and-url-shortening-api/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSS3 Lesson 3: Background Information is Essential</title>
		<link>http://www.davepcguy.com/archive/css3-lesson-3-background-information-is-essential/</link>
		<comments>http://www.davepcguy.com/archive/css3-lesson-3-background-information-is-essential/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 02:34:41 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=969</guid>
		<description><![CDATA[Let&#8217;s have a look at backgrounds. In the previous two tutorials, I&#8217;ve covered borders and opacity. In this tutorial, we&#8217;ll cover some of the basic CSS3 additions to the background properties. If you have no idea how to deal with backgrounds in CSS, read my tutorial on backgrounds pre-CSS3. CSS3 is gaining momentum in the]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=css,Design,formatting,lesson,webpage,website" height="61" width="50" /><br />
			</a>
		</div>
<p>Let&#8217;s have a look at backgrounds. In the previous two tutorials, I&#8217;ve covered <a title="CSS3 Borders Tutorial" href="http://www.davepcguy.com/archive/css3-lesson-2-all-about-borders/">borders</a> and <a title="Border Radius and Opacity tutorial" href="http://www.davepcguy.com/archive/css-lesson-7-border-radius-and-opacity/">opacity</a>. In this tutorial, we&#8217;ll cover some of the basic CSS3 additions to the background properties. If you have no idea how to deal with backgrounds in CSS, read <a title="CSS lesson 1 text properties and backgrounds" href="http://www.davepcguy.com/archive/css-lesson-1/">my tutorial</a> on backgrounds pre-CSS3. CSS3 is gaining momentum in the Web development world and many properties are already supported by most browsers (Firefox, Konqueror, Safari, and Chrome) as well as some minor browser (Opera). If you want to stay on top of the game, you have to learn the new stuff and employ the new techniques you&#8217;re presented with.</p>
<p>In this tutorial, I&#8217;m going to cover:</p>
<ul>
<li>background sizes</li>
<li>multiple backgrounds</li>
<li>background origin/clip</li>
</ul>
<p><span id="more-969"></span><br />
I will provide illustrations as to what each property looks like and you can also view my CSS3 <a title="testing sample for CSS3 backgrounds" href="http://test.davepcguy.com/scripts/CSS3test/secondtest.html">testing sample</a> that features this tutorial&#8217;s properties (among others). The properties will be compatible with both webkit (Safari and Chrome) and the Mozilla engine. Internet Explorer, unfortunately, does not yet support most CSS3 properties. I&#8217;d like to also note that I use a Mozilla Firefox 3.5.2 (which apparently has tons of trouble using ANY of these properties) and Chrome 3.0.195.33 (which seems to render everything perfectly).</p>
<hr />
</p>
<hr />
<h1><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/backgroundsize.png"><img class="size-full wp-image-974 aligncenter" title="backgroundsize" src="http://www.davepcguy.com/wp-content/uploads/2009/12/backgroundsize.png" alt="backgroundsize" width="498" height="111" /></a></h1>
<hr />The <strong>background-size </strong>property is very straight forward. You simply choose the width and the height as the values. You can use percentages, pixels, and other measurements.</p>
<p>First, why do we use this? Well, let&#8217;s say you have an image that&#8217;s too big or too small and you want to resize it without using photoshop or another tool. There are few reasons why you&#8217;d want that. Let&#8217;s say you want the same image on one website to be 400&#215;500 px while on another site, you want it to be 200&#215;250 yet you don&#8217;t want to create the extra file.</p>
<p>In my example, I have a strangely sized logo that is 474 px by 185 px. Now, I want it to be about 90 px tall, so that&#8217;s be 231 width. Here&#8217;s what the code would look like:</p>
<pre class="brush: css;">
background:url(background1.png) no-repeat center;
	-webkit-background-size: 231px 90px;
	-moz-background-size: 231px 90px;
	-o-background-size: 231px 90px;
	-khtml-background-size: 231px 90px;
background-size: 231px 90px;
</pre>
<p>This code should show up properly on the above-mentioned browsers. I&#8217;ve had no trouble with Chrome but my Firefox is being stubborn. The result should look something like this:</p>
<p style="text-align: center;">
<div id="attachment_971" class="wp-caption aligncenter" style="width: 528px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/backgrounds1.PNG"><img class="size-full wp-image-971 " title="css3 backgrounds size" src="http://www.davepcguy.com/wp-content/uploads/2009/12/backgrounds1.PNG" alt="correctly rendered background" width="518" height="274" /></a><p class="wp-caption-text">correctly rendered background</p></div>
<p>As opposed to this:</p>
<p style="text-align: left;">
<div id="attachment_972" class="wp-caption aligncenter" style="width: 530px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/backgrounds2.png"><img class="size-full wp-image-972 " title="Background size" src="http://www.davepcguy.com/wp-content/uploads/2009/12/backgrounds2.png" alt="incorrectly rendered background" width="520" height="186" /></a><p class="wp-caption-text">incorrectly rendered background</p></div>
<p>Note that I am creating these images as I go so whenever I add more backgrounds and use other CSS3 properties, my <a title="CSS3 testing website" href="http://test.davepcguy.com/scripts/CSS3test/secondtest.html">testing</a> site will look differently.</p>
<p style="text-align: center;">
<p style="text-align: center;"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/multiplebackgrounds.png"><img class="size-full wp-image-979 aligncenter" title="multiplebackgrounds" src="http://www.davepcguy.com/wp-content/uploads/2009/12/multiplebackgrounds.png" alt="multiplebackgrounds" width="523" height="117" /></a></p>
<hr />Ever wished you could stack multiple backgrounds without having to create multiple divs? Well, that&#8217;s what this new background extension property does. You can stack multiple backgrounds and using the rgba () value, you can even change opacity of color-based backgrounds.</p>
<p>Here&#8217;s the concept. Okay, so on my example page, I want the background to have a greyish background with a slight gradient. I&#8217;ll make a pixel wide pretty long strip that goes from white to nothingness on top of an actual grey background. On top of all that, I&#8217;d love to add some kind of a swirl on the left and a nice swirl in the right corner. Let&#8217;s see how that&#8217;ll look in code:</p>
<pre class="brush: css;">
.bgr {
background: rgba(115, 115, 115, .8);
background-image:url(gradient.png), url(swirl1.png), url(swirl2.png);
background-position: top left, top left, bottom right;
background-repeat:repeat-x, no-repeat, no-repeat;
background-attachment: fixed;
}
</pre>
<p>Easy concept. I used the original <strong>backbground</strong> property and used the new <strong>rgba()</strong> value for the background. Next I used the <strong>background-image</strong> property for the images, all separated by commas, don&#8217;t forget that. Next I declared the <strong>background-position</strong> and <strong>background-repeat</strong> the same way. The <strong>background-attachment</strong> is for fun.</p>
<p>Now since I&#8217;m really lazy and I don&#8217;t feel like creating my own swirls in illustrator, I used some wonderful free online <a title="swirls brushes" href="http://fbrushes.com/category/swirls/">brushes</a>. Also, I had a lot of trouble making this work in short-hand (ie. background: url(gradient.png) top left repeat-x, url(swirl1.png) top left no-repeat, and so on). Unfortunately, it only works with Webkit (ie Safari and Chrome) and I haven&#8217;t been able to make it work on Firefox. It should work in coming Firefox releases. Check out my testing site for a <a title="CSS3 testing website" href="http://test.davepcguy.com/scripts/CSS3test/secondtest.html">live example</a>.</p>
<p>Here&#8217;s what it should look like:</p>
<p style="text-align: left;">
<div class="mceTemp mceIEcenter">
<dl id="attachment_985" class="wp-caption aligncenter" style="width: 624px;">
<dt class="wp-caption-dt"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/multiplebackgrounds2.png"><img class="size-large wp-image-985 " title="multiple backgrounds" src="http://www.davepcguy.com/wp-content/uploads/2009/12/multiplebackgrounds2-1024x563.png" alt="multiple backgrounds" width="614" height="338" /></a></dt>
</dl>
</div>
<p style="text-align: left;">It looks pretty nice, doesn&#8217;t it? <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I like it. I&#8217;ll probably employ it in some future websites too.</p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: center;"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip.png"><img class="aligncenter size-full wp-image-986" title="originclip" src="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip.png" alt="originclip" width="498" height="111" /></a></p>
<hr />Let&#8217;s look at <strong>background-origin </strong>and <strong>background-clip</strong>. The origin comes first in the title, so it will come first in my explanation. Basically, origin tells the browser where the background image should originate. Should it start where the border ends? Should it start where padding ends? Should it start where the content ends?</p>
<p>This concerns the<a title="border padding and fonts CSS lesson 2" href="http://www.davepcguy.com/archive/css-lesson-2-fonts-padding-and-border/"> box theory</a> and adds to the complications of it. This also concerns the <strong>background-position</strong> property that I used in the previous example. CSS3 Info has a great <a title="css3 info background origin and clip" href="http://www.css3.info/preview/background-origin-and-background-clip/">article</a> that shows all of the different results you can get with clip and origin properties. It&#8217;s useful, but not the best. I&#8217;ll be using the following image to indicate all the different background origins:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip2.png"><img class="aligncenter size-full wp-image-990" title="originclip" src="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip2.png" alt="originclip" width="150" height="123" /></a>The different values you can use are <strong>border-box</strong>, <strong>padding-box</strong>, and <strong>content-box</strong>. While using this property add the &#8220;-moz-&#8221; and &#8220;-webkit-&#8221; prefixes to the properties. Once again, I&#8217;m having trouble making it work in firefox. It might work for you, but it didn&#8217;t work for me. Here&#8217;s the CSS I used:</p>
<pre class="brush: css;">
background: url(swirl3.png) no-repeat bottom right;
background-origin: padding-box;
-moz-background-origin: padding-box;
-webkit-background-origin: padding-box;
</pre>
<p>Of course, I used different positions for different divs. I added some extra borders and padding for effect but go ahead and check out my <a title="CSS3 example testing site" href="http://test.davepcguy.com/scripts/CSS3test/secondtest.html">example site</a>. If it doesn&#8217;t work, here&#8217;s a screenshot:</p>
<p style="text-align: left;"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip3.png"><img class="aligncenter size-full wp-image-991" title="originclip" src="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip3.png" alt="originclip" width="449" height="348" /></a>Here&#8217;s the rundown of the properties:</p>
<ol>
<li>border-box</li>
<li>padding-box</li>
<li>content-box</li>
</ol>
<p>As you can see, <strong>border-box</strong> puts the background image into the border, <strong>padding-box</strong> sits right outside the border (or at the end of the padding), <strong>content-box</strong> puts the background inside the content area.</p>
<p>Let&#8217;s look at <strong>background-clip </strong>which has two different values, <strong>border </strong>and <strong>padding</strong>. Using <strong>border</strong> will enable the background to be visible ABOVE the border area. Padding box does the same except the background will be visible above the padding area and not the border area.</p>
<p>I&#8217;ll use the following swirl to show you how this works:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/swirl4.png"><img class="aligncenter size-full wp-image-992" title="swirl" src="http://www.davepcguy.com/wp-content/uploads/2009/12/swirl4.png" alt="swirl" width="105" height="111" /></a>The first example with the green swirl used the <strong>padding</strong> while the next one will use the <strong>border </strong>value. You won&#8217;t see much difference in most of the swirls (ie between the green and the red) but when you look on the bottom left red swirl, you will notice that part of the swirl is visible in the dashed border. That is basically all the difference you will see between the <strong>border </strong>and <strong>padding </strong>values. Here&#8217;s a close-up picture:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip4.png"><img class="aligncenter size-full wp-image-994" title="originclip" src="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip4.png" alt="originclip" width="193" height="143" /></a>Here&#8217;s the green swirl:</p>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip5.png"><img class="aligncenter size-full wp-image-995" title="origin clip" src="http://www.davepcguy.com/wp-content/uploads/2009/12/originclip5.png" alt="origin clip" width="195" height="153" /></a>Once again though, this feature fails in Mozilla. Here&#8217;s the CSS for the last DIV on the page (where the advertisement is):</p>
<pre class="brush: css;">

background: url(swirl4.png) no-repeat top right;
 -webkit-background-origin: content-box;
 -moz-background-origin: content-box;
 -moz-background-clip: border;
 -webkit-background-clip: border;
background-clip: border;
</pre>
<p style="text-align: center;"><img class="size-full wp-image-997 aligncenter" title="conclusion" src="http://www.davepcguy.com/wp-content/uploads/2009/12/conclusion.png" alt="conclusion" width="498" height="111" /></p>
<hr />
Well, here&#8217;s my conclusion. I found some great use for the multiple backgrounds on my <a title="CSS3 testing website" href="http://test.davepcguy.com/scripts/CSS3test/secondtest.html">testing site</a>. Actually, all of them are pretty useful. I wish there was more support for it. I may have erred but it seems unlikely since all of the properties show up alright in Chrome. I hope you enjoyed my tutorial and look out for some more in the future!</p>
<p>Here&#8217;s the final website:</p>
<p style="text-align: center;"><img class="aligncenter size-large wp-image-1000" title="testing" src="http://www.davepcguy.com/wp-content/uploads/2009/12/testing1-1024x562.png" alt="testing" width="614" height="337" /><img class="aligncenter size-large wp-image-1001" title="testing 2" src="http://www.davepcguy.com/wp-content/uploads/2009/12/testing2-1024x272.png" alt="testing 2" width="614" height="163" /></p>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;bodytext=Let%27s%20have%20a%20look%20at%20backgrounds.%20In%20the%20previous%20two%20tutorials%2C%20I%27ve%20covered%20borders%20and%20opacity.%20In%20this%20tutorial%2C%20we%27ll%20cover%20some%20of%20the%20basic%20CSS3%20additions%20to%20the%20background%20properties.%20If%20you%20have%20no%20idea%20how%20to%20deal%20with%20backgrounds%20in%20CSS%2C%20r" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;notes=Let%27s%20have%20a%20look%20at%20backgrounds.%20In%20the%20previous%20two%20tutorials%2C%20I%27ve%20covered%20borders%20and%20opacity.%20In%20this%20tutorial%2C%20we%27ll%20cover%20some%20of%20the%20basic%20CSS3%20additions%20to%20the%20background%20properties.%20If%20you%20have%20no%20idea%20how%20to%20deal%20with%20backgrounds%20in%20CSS%2C%20r" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;t=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;annotation=Let%27s%20have%20a%20look%20at%20backgrounds.%20In%20the%20previous%20two%20tutorials%2C%20I%27ve%20covered%20borders%20and%20opacity.%20In%20this%20tutorial%2C%20we%27ll%20cover%20some%20of%20the%20basic%20CSS3%20additions%20to%20the%20background%20properties.%20If%20you%20have%20no%20idea%20how%20to%20deal%20with%20backgrounds%20in%20CSS%2C%20r" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Let%27s%20have%20a%20look%20at%20backgrounds.%20In%20the%20previous%20two%20tutorials%2C%20I%27ve%20covered%20borders%20and%20opacity.%20In%20this%20tutorial%2C%20we%27ll%20cover%20some%20of%20the%20basic%20CSS3%20additions%20to%20the%20background%20properties.%20If%20you%20have%20no%20idea%20how%20to%20deal%20with%20backgrounds%20in%20CSS%2C%20r" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;t=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;s=Let%27s%20have%20a%20look%20at%20backgrounds.%20In%20the%20previous%20two%20tutorials%2C%20I%27ve%20covered%20borders%20and%20opacity.%20In%20this%20tutorial%2C%20we%27ll%20cover%20some%20of%20the%20basic%20CSS3%20additions%20to%20the%20background%20properties.%20If%20you%20have%20no%20idea%20how%20to%20deal%20with%20backgrounds%20in%20CSS%2C%20r" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-3-background-information-is-essential%2F&amp;title=CSS3%20Lesson%203%3A%20Background%20Information%20is%20Essential" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/css3-lesson-3-background-information-is-essential/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS3 Lesson 2: All About Borders</title>
		<link>http://www.davepcguy.com/archive/css3-lesson-2-all-about-borders/</link>
		<comments>http://www.davepcguy.com/archive/css3-lesson-2-all-about-borders/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 15:38:56 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[border]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[lesson]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=936</guid>
		<description><![CDATA[Okay, I&#8217;ve noticed some REALLY cool stuff on CSS3 online, so I thought to myself, how about I make my own experiment and teach you all about how to use this stuff? Here are a couple of resources I&#8217;m using to learn about CSS3: CSS3 Info CSS3 Validator Intro to CSS3 W3 Avenue Net Tuts]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=border,css,formatting,internet,lesson" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/css.png"><img class="aligncenter size-full wp-image-963" title="CSS" src="http://www.davepcguy.com/wp-content/uploads/2009/12/css.png" alt="CSS" width="300" height="200" /></a></p>
<p>Okay, I&#8217;ve noticed some REALLY cool stuff on CSS3 online, so I thought to myself, how about I make my own experiment and teach you all about how to use this stuff?</p>
<p>Here are a couple of resources I&#8217;m using to learn about CSS3:</p>
<ul>
<li><a href="http://www.css3.info">CSS3 Info</a></li>
<li><a href="http://jigsaw.w3.org/css-validator/">CSS3 Validator</a></li>
<li><a href="http://designshack.co.uk/tutorials/introduction-to-css3-part-1-what-is-it">Intro to CSS3</a></li>
<li><a href="http://www.w3avenue.com/2009/06/22/css3-unleashed-tips-tricks-and-techniques/">W3 Avenue</a></li>
<li><a href="http://net.tutsplus.com/tutorials/html-css-techniques/html-5-and-css-3-the-techniques-youll-soon-be-using/">Net Tuts Plus tutorial</a></li>
</ul>
<p>I&#8217;ll start with the topic that everyone is concerned about. BORDERS! Okay, why are borders so important? Well, In the Web 2.0 design standard, it&#8217;s all about opacity, rounded corners, shadows, and everything else that&#8217;s just super awesome looking. I&#8217;ve already <a href="http://www.davepcguy.com/archive/css-lesson-7-border-radius-and-opacity/">explained </a>the rounded corners and opacity previously. So, I&#8217;ll skip that part. If you&#8217;re this far, you should probably learn the basics about CSS standards of <a href="http://www.davepcguy.com/archive/css-lesson-2-fonts-padding-and-border/">borders</a> and the markup.<br />
<span id="more-936"></span></p>
<h1>Border Color</h1>
<p>Okay, perhaps not necessarily &#8220;border color&#8221; but rather &#8220;border gradient&#8221; because that&#8217;s all border color is going to be used for in the future <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> .<br />
It&#8217;s currently supported solely by Mozilla Firefox, which is rather unfortunate for all you IE, Chrome, and Safari users.<br />
What does it do? The property is &#8220;<strong>-moz-border-*side*-colors: value</strong>&#8220;, the sides are &#8220;top, bottom, left, right&#8221;. Well, the usual. The problem here is that you have to set up each side. There is no short hand as far as I&#8217;m aware (I&#8217;ve already tried a few variations but nothing worked).<br />
Here&#8217;s what you have to do:</p>
<pre class="brush: css;">
border: 4px solid;
	-moz-border-top-colors: #000099 #0033CC #0066CC #0099CC;
	-moz-border-bottom-colors: #000099 #0033CC #0066CC #0099CC;
	-moz-border-left-colors: #000099 #0033CC #0066CC #0099CC;
	-moz-border-right-colors: #000099 #0033CC #0066CC #0099CC;
</pre>
<p>You&#8217;ll have to set up the border separately, set the pixel size according to how thick you want the border to be. It&#8217;s usually safe to set the pixel width to the number of colors used. Four for each gradient color (#000099 through #0099CC). If you set the width of the border to be thicker than 4px, the last color in the set will be repeated (#0099CC).<br />
If you view my <a href="http://test.davepcguy.com/scripts/CSS3test/index.html">example</a>, you&#8217;ll notice how differently each border looks with different widths (3px 7px 10px and 4px in a clockwise manner starting with the top). If you can&#8217;t see it, here&#8217;s a screenshot:</p>
<div class="wp-caption aligncenter" style="width: 441px"><a href="http://screenshotuploader.com/screen/QWcgJOBsMS/" target="_blank"><img title="Screenshot of CSS3 example" src="http://screenshotuploader.com/img/QWcgJOBsMS.jpg" border="0" alt="" width="431" height="113" /></a><p class="wp-caption-text">Screenshot of CSS3 example</p></div>
<p>That&#8217;s it for the border-color</p>
<hr /></p>
<hr />
<h1>Border Image</h1>
<p>Border image is another border property that shows a lot of promise. Basically, it&#8217;s a property that allows you to use custom specific images that will go around a specific area. Instead of just using lines (or gradients described above), we can insert images for the border. It&#8217;s a really tricky property and there is no real documentation anywhere that explains it thoroughly.<br />
Here&#8217;s the property &#8220;<strong>-*browser*-border-image:</strong>&#8221; for *browser*, you&#8217;ll have to use both &#8220;webkit&#8221; and &#8220;moz&#8221;, and even &#8220;o&#8221; (for opera) and &#8220;khtml&#8221; (konqueror). &#8220;border-image&#8221; is a shortcut for &#8220;-*browser*-border-*side*-image-&#8221;, and *side* works the same way as before.<br />
The second part of our little CSS3 definition is the &#8220;value&#8221; which is in this order: &#8220;url(image.png) slicewidth stretch&#8221;, you also have to use the &#8220;border-width&#8221; property.</p>
<pre class="brush: css;">
#borderedcontent {
 border-width: 10px;
-webkit-border-image: url(border.png) 10 stretch;
-moz-border-image: url(border.png) 10 stretch;

}
</pre>
<p>Again, check out my <a title="example css3 test" href="http://test.davepcguy.com/scripts/CSS3test/index.html">example</a>.</p>
<p>As far as I can tell, the whole art of doing this is slicing the images right. If you have an image that is 99&#215;99 pixels, such as the one below:</p>
<p><img class="alignleft" src="http://test.davepcguy.com/scripts/CSS3test/border2.jpg" alt="" width="99" height="99" />Now, I used a 33 point cutting, so that every 33 points, the images get cut (in all different ways). Once that is done (creating 33 x 33 pixel squares), the second value defines what happens to that little squares. In this case, each square is actually a single dot. I used this image as the second example on my example page. I set the &#8220;stretch&#8221; property to &#8220;stretch round&#8221; which made the top and bottom &#8220;round&#8221; and the sides &#8220;stretch&#8221; (by sides, I mean the middle row of squares). I know this is pretty confusing and it is even for me, but soon enough, it&#8217;ll make sense to you.</p>
<p>The <strong>round</strong> property scales the &#8220;squares&#8221; or &#8220;slices&#8221; of the original image in a way to incorporate the squares in a repeating fashion but so that it only includes WHOLE slices and not parts.</p>
<p>The <strong>repeat</strong> property does just that, it repeats the element, unscaled and thus results in incomplete repetitions of some slices. <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The <strong>stretch</strong> property does its usual business, it stretches each part to fill the whole area.</p>
<p>The <strong>border-width </strong>sets the width of the border and in the case of image-border, it helps scale the slices again to fulfill the whole width of the border. You can also set the width to <strong>auto</strong> which uses the original width of the image slices as width. I used the &#8220;auto width&#8221; property on my second example (creates a pretty funky image)</p>
<p>Like I said, the trickiest part of the whole process is creating the slices. Oh, and remember that if you want to create ONLY the border images, you&#8217;ll have to create a blank middle and slice that out too.</p>
<p>Refer to the <a title="Border Image CSS3 W3 documentation" href="http://www.w3.org/TR/css3-background/#the-border-image">W3 Documentation</a>, which, unlike in other cases, actually provides a comprehensive overview of the property. Check out the different examples and see what you can find out.</p>
<p>There&#8217;s also another website that deals with slicing and other methods to use border-image <a title="border image CSS3 Ninja" href="http://www.lrbabe.com/sdoms/borderImage/index.html">here</a>.</p>
<p>And I found a great <a title="speech bubble CSS3 border image" href="http://brightchimp.com/2008/09/07/hand-drawn-speac-bubble-using-css3-border-image/">example</a> on how to use this property.</p>
<p>Here&#8217;s my last example:</p>
<p>go back  to my CSS3 <a title="CSS3 example testing site" href="http://test.davepcguy.com/scripts/CSS3test/index.html">testing page</a> and you&#8217;ll see a third example on the bottom. Here, I used the &#8220;stretch&#8221; property in combination with the right slicing. Here&#8217;s how I sliced up the image:</p>
<div id="attachment_948" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/borderimage.png"><img class="size-medium wp-image-948" title="sliced image" src="http://www.davepcguy.com/wp-content/uploads/2009/12/borderimage-300x299.png" alt="sliced image" width="300" height="299" /></a><p class="wp-caption-text">sliced image</p></div>
<p>And it worked! Somewhat. My border had to be about 30 px which really distorted the image. Oh, also, the slicing length is measure from the edge toward the center. ie, 40px from the right etc. Again, here are the screenshots:</p>
<div id="attachment_950" class="wp-caption aligncenter" style="width: 307px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/borderimage2.PNG"><img class="size-medium wp-image-950" title="Border examples" src="http://www.davepcguy.com/wp-content/uploads/2009/12/borderimage2-297x300.PNG" alt="Border examples" width="297" height="300" /></a><p class="wp-caption-text">Border examples</p></div>
<h1>Box Shadow</h1>
<p>Box Shadow is the last border-like property. I guess we could classify it under backgrounds as well but I&#8217;m including it here anyways. The property is EXACTLY like the <strong>text-shadow</strong> property described in an <a title="CSS Lesson 1 text properties" href="http://www.davepcguy.com/archive/css-lesson-1/#text">earlier tutorial</a> except now, it involves a whole area.</p>
<p>Let&#8217;s look at the property a bit closer:</p>
<blockquote><p>h1 {</p>
<p>box-shadow: x-offset y-offset blur color;</p>
<p>}</p></blockquote>
<pre class="brush: css;">
h1 {
box-shadow: 2px 1px 3px #000;
}
</pre>
<p>Once again, you&#8217;ll have to add the &#8220;-*browser*-&#8221; part to the property again because it&#8217;s not a &#8220;standard&#8221; property yet. So again <strong>-moz-box-shadow</strong> and <strong>-webkit-box-shadow</strong>. In the example, you don&#8217;t necessarily have to include the color of the shadow, the default will be black.  If you look at my <a title="CSS3 testing website" href="http://test.davepcguy.com/scripts/CSS3test/index.html">example</a>, you&#8217;ll see that it&#8217;s a pretty nice property <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  For all of you who can&#8217;t view it, here&#8217;s the screenshot (*note the original example uses a green shadow):</p>
<div id="attachment_953" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/boxshadow.PNG"><img class="size-medium wp-image-953" title="boxshadow" src="http://www.davepcguy.com/wp-content/uploads/2009/12/boxshadow-300x85.PNG" alt="Box Shadow" width="300" height="85" /></a><p class="wp-caption-text">Box Shadow</p></div>
<p>One thing you can do in mozilla firefox, and nowhere else, is an inner shadow by adding <strong>inset</strong> to your property value:</p>
<pre class="brush: css;">
div {
-moz-box-shadow: inset 1px 3px 2px;
}
</pre>
<p>That results in the second example on my <a title="example css3 test" href="http://test.davepcguy.com/scripts/CSS3test/index.html">example page</a>.</p>
<div id="attachment_956" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/12/boxshadow2.PNG"><img class="size-medium wp-image-956" title="Inner Box Shadow" src="http://www.davepcguy.com/wp-content/uploads/2009/12/boxshadow2-300x76.PNG" alt="Inner Box Shadow" width="300" height="76" /></a><p class="wp-caption-text">Inner Box Shadow</p></div>
<h1>Conclusion</h1>
<p>CSS3 is still in works, and as you might have noticed, many of these properties require the &#8220;-*browser*-&#8221; add-on at the beginning. Once CSS3 becomes a standard, we&#8217;ll be able to use all of these freely. Also, I regret to inform you that IE does not have any quick work around yet but apparently the new<a title="IE 9 CSS3 Support" href="http://www.dave-woods.co.uk/index.php/internet-explorer-9-css3-support/"> IE9</a> should work with CSS3 properties&#8230;finally.</p>
<p>I hope you enjoyed my tutorial and I can&#8217;t wait to show you some more CSS3 stuff!</p>
<hr />
</p>
<hr />



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;bodytext=%0D%0A%0D%0AOkay%2C%20I%27ve%20noticed%20some%20REALLY%20cool%20stuff%20on%20CSS3%20online%2C%20so%20I%20thought%20to%20myself%2C%20how%20about%20I%20make%20my%20own%20experiment%20and%20teach%20you%20all%20about%20how%20to%20use%20this%20stuff%3F%0D%0A%0D%0AHere%20are%20a%20couple%20of%20resources%20I%27m%20using%20to%20learn%20about%20CSS3%3A%0D%0A%0D%0A%09CSS3%20Info%0D%0A%09C" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;notes=%0D%0A%0D%0AOkay%2C%20I%27ve%20noticed%20some%20REALLY%20cool%20stuff%20on%20CSS3%20online%2C%20so%20I%20thought%20to%20myself%2C%20how%20about%20I%20make%20my%20own%20experiment%20and%20teach%20you%20all%20about%20how%20to%20use%20this%20stuff%3F%0D%0A%0D%0AHere%20are%20a%20couple%20of%20resources%20I%27m%20using%20to%20learn%20about%20CSS3%3A%0D%0A%0D%0A%09CSS3%20Info%0D%0A%09C" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;t=CSS3%20Lesson%202%3A%20All%20About%20Borders" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;annotation=%0D%0A%0D%0AOkay%2C%20I%27ve%20noticed%20some%20REALLY%20cool%20stuff%20on%20CSS3%20online%2C%20so%20I%20thought%20to%20myself%2C%20how%20about%20I%20make%20my%20own%20experiment%20and%20teach%20you%20all%20about%20how%20to%20use%20this%20stuff%3F%0D%0A%0D%0AHere%20are%20a%20couple%20of%20resources%20I%27m%20using%20to%20learn%20about%20CSS3%3A%0D%0A%0D%0A%09CSS3%20Info%0D%0A%09C" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=%0D%0A%0D%0AOkay%2C%20I%27ve%20noticed%20some%20REALLY%20cool%20stuff%20on%20CSS3%20online%2C%20so%20I%20thought%20to%20myself%2C%20how%20about%20I%20make%20my%20own%20experiment%20and%20teach%20you%20all%20about%20how%20to%20use%20this%20stuff%3F%0D%0A%0D%0AHere%20are%20a%20couple%20of%20resources%20I%27m%20using%20to%20learn%20about%20CSS3%3A%0D%0A%0D%0A%09CSS3%20Info%0D%0A%09C" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;t=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;s=%0D%0A%0D%0AOkay%2C%20I%27ve%20noticed%20some%20REALLY%20cool%20stuff%20on%20CSS3%20online%2C%20so%20I%20thought%20to%20myself%2C%20how%20about%20I%20make%20my%20own%20experiment%20and%20teach%20you%20all%20about%20how%20to%20use%20this%20stuff%3F%0D%0A%0D%0AHere%20are%20a%20couple%20of%20resources%20I%27m%20using%20to%20learn%20about%20CSS3%3A%0D%0A%0D%0A%09CSS3%20Info%0D%0A%09C" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=CSS3%20Lesson%202%3A%20All%20About%20Borders%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=CSS3%20Lesson%202%3A%20All%20About%20Borders&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss3-lesson-2-all-about-borders%2F&amp;title=CSS3%20Lesson%202%3A%20All%20About%20Borders" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/css3-lesson-2-all-about-borders/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CSS Lesson 7: Border Radius and Opacity</title>
		<link>http://www.davepcguy.com/archive/css-lesson-7-border-radius-and-opacity/</link>
		<comments>http://www.davepcguy.com/archive/css-lesson-7-border-radius-and-opacity/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 21:46:02 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=891</guid>
		<description><![CDATA[Border Radius and Opacity I&#8217;ve noticed some hundred tweets on CSS3, every day. Check out the CSS3 Watcher for random updates. They actually mention really awesome and useful tutorials. So now, let&#8217;s look at some basic features that actually work cross-browser (with some tweaks). You can check some of the usage on two version of]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=background,css,lesson,text,website" height="61" width="50" /><br />
			</a>
		</div>
<div style="border: 1px solid black; border-radius: 15px; -moz-border-radius: 15px;-webkit-border-radius: 15px; text-align: center; background-color: #0066CC; color: black; padding-bottom: 15px ">
<h1>Border Radius and <span style="opacity: 0.6;filter:alpha(opacity=60); background-color: white; padding: 10px; border-radius: 15px; -moz-border-radius: 15px;-webkit-border-radius: 15px;  "> Opacity</span></h1>
</div>
<p>I&#8217;ve noticed some hundred tweets on CSS3, every day. Check out the<a title="CSS3 Watcher twitter profile" href="http://twitter.com/css3watcher"> CSS3 Watcher </a>for random updates. They actually mention really awesome and useful tutorials. So now, let&#8217;s look at some basic features that actually work cross-browser (with some tweaks). You can check some of the usage on two version of one of my projects: the <a title="alpha age tester" href="http://test.davepcguy.com/scripts/agetester/index.php">alpha</a>, which utilizes rounded corners, and the<a title="beta age tester" href="http://test.davepcguy.com/scripts/agetester/final.php"> beta</a>, which utilizes a lot of opacity features.</p>
<p>I&#8217;ll show you some fun features as well as ways to get around them.<br />
<span id="more-891"></span></p>
<h1>Rounded Corners</h1>
<p>Creating rounded corners has always been a challenge. People have used several methods to accomplish this. One was by creating corner images to over-lap the background and make the square part of the corner transparent. I won&#8217;t explain that method, I don&#8217;t use it. But let&#8217;s look at the CSS3 write up:</p>
<pre class="brush: css;">
border-radius: 15px;
  -moz-border-radius: 15px;
  -webkit-border-radius: 15px;
</pre>
<p>The short-hand property works very well here. It&#8217;s explained in my <a title="lesson 2 fonts padding and border" href="http://www.davepcguy.com/archive/css-lesson-2-fonts-padding-and-border/">CSS Lesson 2</a>. But let&#8217;s go over this in detail:</p>
<p><strong>border-radius</strong> is the proper property mark-up in CSS3. There are variations to accommodate each corner of the object:</p>
<blockquote><p>border-top-right-radius:<br />
border-top-left-radius:<br />
border-bottom-right-radius:<br />
border-bottom-left-radius:</p></blockquote>
<p>There, you can specify the exact curvature of each corner. You can do that in pixels, em, and other such length measurements. The larger the measurement, the more curved the corner will be.<br />
Now, we all know that most browser today do not support pure CSS3 mark-up. There are two specific properties you can use.<br />
For Mozilla, use these:</p>
<blockquote><p>-moz-border-radius:<br />
-moz-border-topleft:<br />
-moz-border-topright:<br />
-moz-border-bottomleft:<br />
-moz-border-bottomright:</p></blockquote>
<p>Yay! These work just as well and the same way as the original CSS3 markup.<br />
For Safari and Chrome, use the following properties:</p>
<blockquote><p>-webkit-border-radius:<br />
-webkit-border-top-left-radius:<br />
-webkit-border-top-right-radius:<br />
-webkit-border-bottom-left-radius:<br />
-webkit-border-bottom-right-radius:</p></blockquote>
<p>But that&#8217;s about it. Unfortunately, none of these apply to Internet Explorer, (as was expected), so when you view my testing sites (links are at the beginning of this article), you won&#8217;t see anything different.</p>
<div id="attachment_895" class="wp-caption aligncenter" style="width: 234px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/11/css1.png"><img class="size-full wp-image-895" title="Input box" src="http://www.davepcguy.com/wp-content/uploads/2009/11/css1.png" alt="Input box" width="224" height="66" /></a><p class="wp-caption-text">Input box</p></div>
<p>Here&#8217;s an input box modified by CSS3. Now to get the input box to look like this is a real problem without CSS but let me show you how you can bypass this CSS method on normal fields of text and html. Let me show you what I mean.<br />
</p>
<h2>The &#8220;Div&#8221; Method</h2>
<div id="attachment_896" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/11/css2.png"><img class="size-medium wp-image-896" title="template diagram" src="http://www.davepcguy.com/wp-content/uploads/2009/11/css2-300x251.png" alt="template diagram" width="300" height="251" /></a><p class="wp-caption-text">template diagram</p></div>
<p>Here&#8217;s a simple template diagram. The code for this would be as following:</p>
<pre class="brush: xml;">
&lt;div id=&quot;container&quot;&gt;
   &lt;div id=&quot;topcontent&quot;&gt;&lt;/div&gt;
   &lt;div id=&quot;content&quot;&gt;
       &lt;div id=&quot;clear&quot;&gt;&lt;/div&gt;
   &lt;/div&gt;
   &lt;div id=&quot;rightbar&quot;&gt;
       &lt;div id=&quot;clear&quot;&gt;&lt;/div&gt;
   &lt;/div&gt;
   &lt;div id=&quot;bottomcontent&quot;&gt;
   &lt;/div&gt;
&lt;/div&gt;
</pre>
<p>Read my <a title="Intro to Divs" href="http://www.davepcguy.com/archive/css-lesson-6-intro-to-divs/">intro to divs</a> to understand this structure better. But first, let me show you what I&#8217;m up to. Now, we know that most internet browsers these days support .PNG files, right? and .PNG files support transparency, yay! Instead of creating a mega background as I did in the case of one of my <a title="A Night Story" href="http://test.davepcguy.com/livestory/walkingman.html">websites</a>, we can simply take the top snippet of the background. Let me show you:</p>
<div id="attachment_897" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/11/css3.png"><img class="size-medium wp-image-897" title="background diagram" src="http://www.davepcguy.com/wp-content/uploads/2009/11/css3-300x243.png" alt="background diagram" width="300" height="243" /></a><p class="wp-caption-text">background diagram</p></div>
<p>You simply crop out the bottom and top into separate files. Make them as small as possible (height wise), let&#8217;s say ten pixels at most. Save them and insert them into the divs like this:</p>
<pre class="brush: css;">
#topcontent {
height: 10px;
background: url(top.png);
width: 100%;
}
</pre>
<p>Do the same for the bottom content and you&#8217;re done! It&#8217;s really this easy and it saves a lot of space. You may have to create another div just for the content and right sidebar, but that all depends on what you&#8217;re doing with the site.<br />
 <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I hope that helped! Let&#8217;s move on to opacity!</p>
<h1>Opacity</h1>
<p>Opacity, yay! Or as you could call it, transparency. It&#8217;s a great CSS3 feature that I absolutely love because there is so much you can do with it. For me, it&#8217;s a great design feature because now, I don&#8217;t have to mess with new images. (I&#8217;ll show you the image method afterward). So let&#8217;s go for it. Here is the basic mark-up:</p>
<pre class="brush: css;">
/* IE */
  filter:alpha(opacity=80);
/* CSS3 standard */
  opacity:0.8;
</pre>
<p>The CSS3 standard works on all browsers besides IE, which, luckily, has a simple work-around. The CSS3 standard works on the principle where &#8220;1&#8243; is completely visible and &#8220;0&#8243; is completely invisible. Anything in between is the opacity setting. The IE standard, works the same way except this time &#8220;100&#8243; is the full opacity and &#8220;0&#8243; is the complete transparency.<br />
Unfortunately, this property has limitations. If used on my standard Div model, on the &#8220;container&#8221;, then not only will the background have a set transparency, but everything within the container will as well, including text, images, and everything else. I&#8217;ve tried to use the &#8220;!important&#8221; mark-up but that does not work either. Also, when another transparency is set, for example, a transparent &#8220;content&#8221; div, it will only subtract from the &#8220;container&#8221; transparency. Thus, when the &#8220;container&#8221; is set to 80 in IE, and .8 in standard, then the &#8220;content&#8221; will start with an 80/.8 transparency. So when you set a transparency of 80/.8 to the &#8220;content&#8221; it will be 80% of the original 80%. I know, confusing, but it makes sense in the end <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h1>Image Method</h1>
<p>Okay, so let&#8217;s say you don&#8217;t want to put with this CSS3 crap, or you want only the background to be transparent. The method is simpler than you think. Create a 1 pixel x 1 pixel .PNG image, whatever color you want it, and set the transparency in the image, and save it. Then use this piece of CSS:</p>
<pre class="brush: css;">
#container {
background: url (transparentimage.png) repeat;
}
</pre>
<p>The image will repeat indefinitely and create a transparent background. If you have an actual picture as a background, set the transparency same way.</p>
<p>So, this was it! I hope you enjoyed my tutorial. Spread the word ^.^<br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;bodytext=%0D%0ABorder%20Radius%20and%20%20Opacity%0D%0A%0D%0AI%27ve%20noticed%20some%20hundred%20tweets%20on%20CSS3%2C%20every%20day.%20Check%20out%20the%20CSS3%20Watcher%20for%20random%20updates.%20They%20actually%20mention%20really%20awesome%20and%20useful%20tutorials.%20So%20now%2C%20let%27s%20look%20at%20some%20basic%20features%20that%20actually%20wor" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;notes=%0D%0ABorder%20Radius%20and%20%20Opacity%0D%0A%0D%0AI%27ve%20noticed%20some%20hundred%20tweets%20on%20CSS3%2C%20every%20day.%20Check%20out%20the%20CSS3%20Watcher%20for%20random%20updates.%20They%20actually%20mention%20really%20awesome%20and%20useful%20tutorials.%20So%20now%2C%20let%27s%20look%20at%20some%20basic%20features%20that%20actually%20wor" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;t=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;annotation=%0D%0ABorder%20Radius%20and%20%20Opacity%0D%0A%0D%0AI%27ve%20noticed%20some%20hundred%20tweets%20on%20CSS3%2C%20every%20day.%20Check%20out%20the%20CSS3%20Watcher%20for%20random%20updates.%20They%20actually%20mention%20really%20awesome%20and%20useful%20tutorials.%20So%20now%2C%20let%27s%20look%20at%20some%20basic%20features%20that%20actually%20wor" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=%0D%0ABorder%20Radius%20and%20%20Opacity%0D%0A%0D%0AI%27ve%20noticed%20some%20hundred%20tweets%20on%20CSS3%2C%20every%20day.%20Check%20out%20the%20CSS3%20Watcher%20for%20random%20updates.%20They%20actually%20mention%20really%20awesome%20and%20useful%20tutorials.%20So%20now%2C%20let%27s%20look%20at%20some%20basic%20features%20that%20actually%20wor" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;t=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;s=%0D%0ABorder%20Radius%20and%20%20Opacity%0D%0A%0D%0AI%27ve%20noticed%20some%20hundred%20tweets%20on%20CSS3%2C%20every%20day.%20Check%20out%20the%20CSS3%20Watcher%20for%20random%20updates.%20They%20actually%20mention%20really%20awesome%20and%20useful%20tutorials.%20So%20now%2C%20let%27s%20look%20at%20some%20basic%20features%20that%20actually%20wor" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-7-border-radius-and-opacity%2F&amp;title=CSS%20Lesson%207%3A%20Border%20Radius%20and%20Opacity" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/css-lesson-7-border-radius-and-opacity/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSS Trick: Disappearing Textbox</title>
		<link>http://www.davepcguy.com/archive/css-trick-disappearing-textbox/</link>
		<comments>http://www.davepcguy.com/archive/css-trick-disappearing-textbox/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:21:45 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[web extras]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=777</guid>
		<description><![CDATA[Remember that trick to show a sub-menu using CSS in my older tutorial? Well, I had an idea for a project of mine, and with a little help from my dear friend Raphael. Last night, I launched my little website project called &#8220;A Night Story&#8221; and made some tweaks. Ignore the story, it&#8217;s just a]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=css,formatting,project,text,web+extras,webpage,website" height="61" width="50" /><br />
			</a>
		</div>
<p>Remember that trick to show a sub-menu using CSS in my <a title="CSS Vertical Navigation" href="http://www.davepcguy.com/archive/css-vertical-navigation/">older tutorial?</a> Well, I had an idea for a project of mine, and with a little help from my dear friend <a title="Raphael Caixeta" href="http://www.raphaelcaixeta.com">Raphael</a>. Last night, I launched my little website project called &#8220;<a title="A Night Story" href="http://test.davepcguy.com/livestory/test.html">A Night Story</a>&#8221; and made some tweaks. Ignore the story, it&#8217;s just a concept. If you hover over the word &#8220;city&#8221; in the text, you&#8217;ll see another textbox appear with more information about the word.<br />
<span id="more-777"></span><br />
The whole concept of the website is to create a story, a swift, easy-to-read story that contains more information than it seems.</p>
<div id="attachment_778" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/span1.png"><img class="size-medium wp-image-778" title="span1" src="http://www.davepcguy.com/wp-content/uploads/2009/10/span1-300x167.png" alt="Hover effect" width="300" height="167" /></a><p class="wp-caption-text">Hover effect</p></div>
<p>So, let me teach you how to create such a hover effect on any word in the text, and on an unlimited amount of words without much work</p>
<h1>The HTML</h1>
<p>First, we have to create an ideal HTML situation that will be easy to describe with CSS later on. First, pick the word, in my case &#8220;city&#8221; and then the text.</p>
<p>We&#8217;ll have to put the whole thing within a &#8220;span&#8221; and then create another &#8220;span&#8221; for the hover text like this:</p>
<pre class="brush: xml;">
&lt;span&gt;&lt;a href=&quot;terms/city.html&quot;&gt;city&lt;/a&gt;&lt;span&gt;the city was large, and dark. People droned on and walked aimlessly through the streets every day. The smog filtered through their lungs. No one could escape the industrialization that overtook and destroyed the greenery that had once been there, the darkness shrouded my moves. &lt;/span&gt;&lt;/span&gt;
</pre>
<p>If you don&#8217;t want to use the &lt;a&gt; tag, then use another tag that you can use as an &#8220;anchor&#8221;, ie so the browser knows its special, a good one to use could be the tag &lt;b&gt;, which will let people know that the bold text is important and hoverable. Otherwise, you can create ids for all these spans and that&#8217;s just too much work. You can try different variations of this formula and see how it works. This is what I did, and it worked out well <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
</p>
<h1>The CSS</h1>
<p>Let&#8217;s focus on the CSS. One thing, I want to do is change the word &#8220;city&#8221; so that it does not appear&#8230;like such a link. Let me show you how I customized the link so that it appears the way it does:</p>
<pre class="brush: css;">
a {
padding: 0px;
margin: 0px;
background-color: #FFFFFF;
}

a:link, a:visited
{
color: #0000CC;
text-decoration: none;
}

a:hover
{
background-color: #369;
color: #fff;
}
</pre>
<p>That creates a nice effect. The underline is gone, the tag has no special padding or a margin. I&#8217;ve also took the the liberty to make its background match the rest of the div (not necessary). Next I changed it so that the color does not change once clicked, but the color of the word will still be different than white. Once hovered, the word will change color and background as shown on my test page.</p>
<p>Let&#8217;s get down to disappearing! Believe it or not, this is so easy, you&#8217;ll be asking yourself why you hadn&#8217;t thought of it:</p>
<pre class="brush: css;">
span&gt;span{
display: none;
position: absolute;
width: 300px;
}
span:hover&gt;span {
display: block;
padding: 5px;
background-color: white;
border: 1px solid black;
}
</pre>
<p>First, I used a strange class: <strong>span&gt;span</strong> means, the span within another span will follow these properties. The text will not display, the position is absolute (so that it will cover other text once hovered over), and the width is nice 300px. You can change the width attribute, and mess around with the position if you wish to. I probably will in the final version.</p>
<p>Next, <strong>span:hover&gt;span</strong> is a pseudo weird class. The <strong>span:hover </strong>class basically is a class that takes effect only when you mouse over the original span. By adding <strong>&gt;span</strong>, we&#8217;ve created something genius. This class is a class that works only once the original span is moused over. Now, we&#8217;re using the <strong>display:block</strong> property to display the nice block of text. I used some padding and added a background color so that the other text won&#8217;t interfere. The border is there only for neatness.</p>
<p>And that&#8217;s it! With just these few steps you&#8217;ve created something that people use javascript for!</p>
<p><strong>Pros:</strong></p>
<p>The pros of using CSS:</p>
<ol>
<li>It is really easy to change the effects</li>
<li> You don&#8217;t have to learn javascript</li>
<li>It works even if the user has javascript disabled</li>
<li>It is faster than javascript because it requires no calculation or parsing</li>
</ol>
<p><strong>Cons:</strong></p>
<p>The Cons of using CSS for this particular effect:</p>
<ol>
<li>less maneuverability</li>
<li>less special effects</li>
<li>looks too simple for some websites</li>
</ol>
<p>With some experimenting and patience, you can create really beautiful drop-down textboxes with custom backgrounds. Well, the possibilities are endless! <img src='http://www.davepcguy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a title="testing site" href="http://test.davepcguy.com/livestory/test.html">Again, go check out my testing site for a demo!</a></p>




Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox&amp;bodytext=Remember%20that%20trick%20to%20show%20a%20sub-menu%20using%20CSS%20in%20my%20older%20tutorial%3F%20Well%2C%20I%20had%20an%20idea%20for%20a%20project%20of%20mine%2C%20and%20with%20a%20little%20help%20from%20my%20dear%20friend%20Raphael.%20Last%20night%2C%20I%20launched%20my%20little%20website%20project%20called%20%22A%20Night%20Story%22%20and%20made%20som" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox&amp;notes=Remember%20that%20trick%20to%20show%20a%20sub-menu%20using%20CSS%20in%20my%20older%20tutorial%3F%20Well%2C%20I%20had%20an%20idea%20for%20a%20project%20of%20mine%2C%20and%20with%20a%20little%20help%20from%20my%20dear%20friend%20Raphael.%20Last%20night%2C%20I%20launched%20my%20little%20website%20project%20called%20%22A%20Night%20Story%22%20and%20made%20som" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;t=CSS%20Trick%3A%20Disappearing%20Textbox" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox&amp;annotation=Remember%20that%20trick%20to%20show%20a%20sub-menu%20using%20CSS%20in%20my%20older%20tutorial%3F%20Well%2C%20I%20had%20an%20idea%20for%20a%20project%20of%20mine%2C%20and%20with%20a%20little%20help%20from%20my%20dear%20friend%20Raphael.%20Last%20night%2C%20I%20launched%20my%20little%20website%20project%20called%20%22A%20Night%20Story%22%20and%20made%20som" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Remember%20that%20trick%20to%20show%20a%20sub-menu%20using%20CSS%20in%20my%20older%20tutorial%3F%20Well%2C%20I%20had%20an%20idea%20for%20a%20project%20of%20mine%2C%20and%20with%20a%20little%20help%20from%20my%20dear%20friend%20Raphael.%20Last%20night%2C%20I%20launched%20my%20little%20website%20project%20called%20%22A%20Night%20Story%22%20and%20made%20som" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;t=CSS%20Trick%3A%20Disappearing%20Textbox&amp;s=Remember%20that%20trick%20to%20show%20a%20sub-menu%20using%20CSS%20in%20my%20older%20tutorial%3F%20Well%2C%20I%20had%20an%20idea%20for%20a%20project%20of%20mine%2C%20and%20with%20a%20little%20help%20from%20my%20dear%20friend%20Raphael.%20Last%20night%2C%20I%20launched%20my%20little%20website%20project%20called%20%22A%20Night%20Story%22%20and%20made%20som" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=CSS%20Trick%3A%20Disappearing%20Textbox%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS%20Trick%3A%20Disappearing%20Textbox&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=CSS%20Trick%3A%20Disappearing%20Textbox&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-trick-disappearing-textbox%2F&amp;title=CSS%20Trick%3A%20Disappearing%20Textbox" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/css-trick-disappearing-textbox/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS Lesson 6: Intro to Divs</title>
		<link>http://www.davepcguy.com/archive/css-lesson-6-intro-to-divs/</link>
		<comments>http://www.davepcguy.com/archive/css-lesson-6-intro-to-divs/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 22:36:44 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
				<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[divs]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[webpage]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.davepcguy.com/?p=686</guid>
		<description><![CDATA[Alright, alright. So I skipped all that fuss with horizontal navbars but that stuff is easy so I&#8217;ll create a short article on it later. Let&#8217;s start with the &#60;div&#62; tag. It&#8217;s what I&#8217;ll be covering. Making use of div&#8217;s with CSS. You&#8217;ll need to know the following before we start the lesson: CSS Lesson]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;source=clrkmck&amp;style=normal&amp;service_api=clrkmck%3AR_a73f58a91ed3515157df75ab6c37730f&amp;hashtags=css,Design,divs,formatting,lesson,text,webpage,website" height="61" width="50" /><br />
			</a>
		</div>
<p>Alright, alright. So I skipped all that fuss with horizontal navbars but that stuff is easy so I&#8217;ll create a short article on it later.</p>
<p>Let&#8217;s start with the &lt;div&gt; tag. It&#8217;s what I&#8217;ll be covering. Making use of div&#8217;s with CSS. You&#8217;ll need to know the following before we start the lesson:</p>
<ul>
<li><a title="CSS Lesson 2: fonts, padding, and border" href="http://www.davepcguy.com/archive/css-lesson-2-fonts-padding-and-border/">CSS Lesson 2</a></li>
<li><a title="CSS Lesson 3: Margin, outlines, and tables" href="http://www.davepcguy.com/archive/css-lesson-3/">CSS Lesson 3</a></li>
<li>as well as basic HTML knowledge</li>
</ul>
<p>If you don&#8217;t how to add CSS to your website, check out my <a title="CSS Intro" href="http://www.davepcguy.com/archive/css-intro/">CSS Intro</a> tutorial and <a title="CSS Lesson 1" href="http://www.davepcguy.com/archive/css-lesson-1/">CSS Lesson 1</a>.<br />
<span id="more-686"></span></p>
<h1>What are &#8220;divs&#8221;?</h1>
<p>A div is basically a section, a chunk of HTML that you can apply the same CSS to. It works similarly to &lt;span&gt; but on larger areas and more complicated HTML. Also, it supports nesting.</p>
<p>A single DIVision can be used, for example, to make a header, another for the navbar. Divs are usually defined using the CSS properties: <strong>margin, padding, border, height, </strong><strong>width, </strong>and <strong>float.</strong></p>
<p>So what can you do with Divs? Well, that&#8217;s the best part. Using divs, you can create multi column websites, you can make the website aligned in the center, instead to the side. You can create rules for large chunks of stuff including text and pictures.</p>
<p>Divs largely replaced the use of tables for page layout, which is great.</p>
<h1>Recognizing Divs</h1>
<p>Now, let&#8217;s look at how divs should be structured, I&#8217;ll be re-making a template I did in PSD a while ago, you can find in <a href="http://www.davepcguy.com/exans-corner/">Exan&#8217;s Corner</a>.</p>
<div id="attachment_735" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/gcg2.jpg"><img class="size-medium wp-image-735" title="gcg2" src="http://www.davepcguy.com/wp-content/uploads/2009/10/gcg2-300x276.jpg" alt="Template" width="300" height="276" /></a><p class="wp-caption-text">Template</p></div>
<p>Right as I&#8217;m looking at it, I can already distinguish four different sections in the template. The first is the header that contains the words &#8220;A Chiropractic Group&#8221;. The second section is the nav bar and the third is the content on the right. The fourth would be the footer. But when you&#8217;re thinking of divs, you have to think differently. This page will contain at least five different divs, if that. I&#8217;d probably cut it up to six or seven different ones. Why? Well let me show you.</p>
<p>NOTE: These are only examples, I am not actually recreating the template above.</p>
<div id="attachment_738" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/div1.png"><img class="size-medium wp-image-738" title="Div illustration" src="http://www.davepcguy.com/wp-content/uploads/2009/10/div1-300x214.png" alt="Div illustration" width="300" height="214" /></a><p class="wp-caption-text">Div illustration</p></div>
<p>Way too confusing, eh? Haha, there are just so many sections. Let me break it down for you and explain why it is this way. Also note that I did not add the &#8220;footer&#8221; div which would be number 7 on the bottom. It works the same way as the top div.<br />
<br />
<strong>1. Header &#8211; </strong>Just a standard div that you&#8217;ll put at the beginning of your &lt;div&gt; tag. It will always be on top unless you set another div for absolute position. First thing you want to do while setting this division up is giving it an id or a class like this: &lt;div id=&#8221;header&#8221;&gt; &lt;/div&gt;.  	Great thing about divs is that you don&#8217;t NEED to put anything in there so let&#8217;s set up the rest of the properties.  	Second step is to set up the width and height using CSS:</p>
<pre class="brush: xml;">
&lt;div id=&quot;header&quot;&gt;&lt;/div&gt;
#header {
width: 100%;
height: 150px;
margin: 0;
background: url(header.png) repeat-x;
}
</pre>
<p>This is basically how we set up all of the divs. Using the &#8220;repeat-x&#8221;, we don&#8217;t need to slice large portions of the header (thus adding to the size of the images needed to be downloaded) and we create a continuous header that will show up the same on all web-browsers/monitors. You&#8217;ll need to separately define the classes and ids for the logo as well as the text inside the header to match the PSD template, you might also have to create another separate div for the logo and one for the text, just in case.</p>
<p><strong>2. Wrapper</strong> &#8211; I&#8217;m sure you&#8217;ve encountered that term before. Whenever you need two or more divs to show up next to each other, you need to &#8220;wrap&#8221; them in another div. In this case, it&#8217;ll be the content area, the content footer, and the sidebar that will be wrapped together. With the wrapper, we can also set it up so that the content shows up in the middle using the property &#8220;margin: 0 auto;&#8221; which will automatically center the content. Here, though, we just need to set up the background and the width of the wrapper using CSS. Once again, assign a class or an id to the div.</p>
<pre class="brush: xml;">
&lt;div id=&quot;wrapper&quot;&gt;
&lt;div id=&quot;sidebar&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;contentwrap&gt;&lt;/div&gt;
&lt;/div&gt;
#wrapper {
width: 900px;
height: 1000px;
}
</pre>
<p>It is also possible to set the height to &#8220;auto&#8221; but if we&#8217;re to do that, let&#8217;s do that as the last thing in the process.</p>
<p><strong>3. Sidebar</strong> &#8211; As you can see, I created a div for the sidebar. Now, if you wanted to create a dynamic sidebar, ie one that changes, and you wish to still use the rounded corners, you will need to include three more divs in the sidebar division. This way, the sidebar itself will serve as another wrapper inside a wrapper.</p>
<div id="attachment_739" class="wp-caption aligncenter" style="width: 160px"><a href="http://www.davepcguy.com/wp-content/uploads/2009/10/div2.png"><img class="size-medium wp-image-739" title="Sidebar div" src="http://www.davepcguy.com/wp-content/uploads/2009/10/div2-150x300.png" alt="Sidebar div" width="150" height="300" /></a><p class="wp-caption-text">Sidebar div</p></div>
<p>You&#8217;d have the top div where you would use the first five or six pixels to create the corners, the bottom div for the same purpose. Also, use only PNG because JPEG does not support transparency. The middle would use a repeating background again. Here&#8217;s how you&#8217;d set it up:</p>
<pre class="brush: xml;">
&lt;div id=&quot;sidebar&quot;&gt;
&lt;div id=&quot;sidebartop&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sidebarmiddle&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;sidebarbottom&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

#sidebar {
height: 600px;
width: 200px;
float: left;
}
#sidebartop{
height: 10px;
background: url(topside.png) no-repeat;
width: auto;
}
#sidebarmiddle {
height: auto;
background: url(sidebar.png) repeat-y;
width: auto;
}
#sidebarbottom {
height: 10px;
background: url(bottomside.png) no-repeat;
width: auto;
}
</pre>
<p>Now you&#8217;ve set up the sidebar. Do you get the idea yet? All you do with divs is set up portions of the page. The problem with this is that the sidebar height will be based on the content inside. For template-making purposes, set the height and change the CSS afterward if needed.</p>
<p>TIP: Create a special class called &#8220;clear&#8221; with these attributes: .clear { clear: both; height: 1px; } and add it at the end of every div that has the property &#8220;float&#8221;</p>
<p><strong>4. Content Wrap: </strong>Here&#8217;s another tricky part. You see how the content has two different sections? One above with articles and one below with a pseudo footer? They&#8217;re aligned together so that means, we need another wrapper. This one will how <strong>5. Content </strong>and <strong>6. Pseudo-footer</strong>. The set up is easy.</p>
<pre class="brush: xml;">
&lt;div id=&quot;contentwrap&quot;&gt;
&lt;div id=&quot;content&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;psfooter&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

#contentwrap {
width: 700px;
height: auto;
float:left;
}
#content {
width: 698px;
height: auto;
}
#psfooter {
width: 698px;
height: auto;
}
</pre>
<p><strong>7. The Footer &#8211; </strong>This is the easiest part and probably the most common on all websites.</p>
<pre class="brush: xml;">
&lt;div id=&quot;footer&quot;&gt;&lt;/div&gt;

#footer {
height: 20px;
width: auto;
margin: 0 auto;
text-align: center;
}
</pre>
<p>That&#8217;s it! This is how you create a website out of a PSD template, basically. And this is how you use divs. It&#8217;s all about setting up the height, width, padding, margins. Really, there is no magic to it.</p>
<p>Altogether, here&#8217;s the basic layout in divs:</p>
<pre class="brush: xml;">
&lt;body&gt;
&lt;div id=&quot;header&quot;&gt;&lt;/div&gt;

&lt;div id=&quot;wrapper&quot;&gt;

 &lt;div id=&quot;sidebar&quot;&gt;
  &lt;div id=&quot;sidebartop&quot;&gt;&lt;/div&gt;
  &lt;div id=&quot;sidebarmiddle&quot;&gt;&lt;/div&gt;
  &lt;div id=&quot;sidebarbottom&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
 &lt;/div&gt;

 &lt;div id=&quot;contentwrap&quot;&gt;
  &lt;div id=&quot;content&quot;&gt;&lt;/div&gt;
  &lt;div id=&quot;psfooter&quot;&gt;&lt;/div&gt;
  &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
 &lt;/div&gt;

&lt;/div&gt;

&lt;div id=&quot;footer&quot;&gt;&lt;/div&gt;

&lt;/body&gt;
</pre>
<p>Using the CSS, you can define the rest of the properties as shown at the beginning (ie. width, height, float, margins, background, border etc).</p>
<p>In my next tutorial, I&#8217;ll be covering the correct way to slice a PSD template for HTML/CSS use. Remember to use the same measurements in photoshop as in CSS and HTML!</p>
<h1>Overview</h1>
<p>A &lt;div&gt; or division, is a section of a webpage that shares the same properties. They&#8217;re easily recognizable, there is a div for a sidebar, for the content, the header, and the footer.</p>
<p>If you want multiple divs next to each other, create a &#8220;wrapper&#8221; div that will group the multiple divs together. Next, make the divs &#8220;float:left&#8221; to ensure they&#8217;ll be next to each other. After every &#8220;float&#8221;ing div, employ the &#8220;clear&#8221; div with the properties &#8220;clear:both; height: 1px&#8221;.</p>
<p>If you want to have rounded corners on your webpage and still retain a variable height of the division, create three separate divs nested in the original. One for the top, one for the middle, and one for the bottom. The top and bottom will contain the part of the background with the rounded corners. USE PNG!</p>
<p>&lt;div&gt;s may look confusing at first but once you start working with them, you&#8217;ll appreciate the options they provide you with.</p>
<p>See you next time!<br />
</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.printfriendly.com/print?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;partner=sociable" title="Print"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/printfriendly.png" title="Print" alt="Print" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;bodytext=Alright%2C%20alright.%20So%20I%20skipped%20all%20that%20fuss%20with%20horizontal%20navbars%20but%20that%20stuff%20is%20easy%20so%20I%27ll%20create%20a%20short%20article%20on%20it%20later.%0D%0A%0D%0ALet%27s%20start%20with%20the%20%26lt%3Bdiv%26gt%3B%20tag.%20It%27s%20what%20I%27ll%20be%20covering.%20Making%20use%20of%20div%27s%20with%20CSS.%20You%27ll%20need%20to%20" title="Digg"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;notes=Alright%2C%20alright.%20So%20I%20skipped%20all%20that%20fuss%20with%20horizontal%20navbars%20but%20that%20stuff%20is%20easy%20so%20I%27ll%20create%20a%20short%20article%20on%20it%20later.%0D%0A%0D%0ALet%27s%20start%20with%20the%20%26lt%3Bdiv%26gt%3B%20tag.%20It%27s%20what%20I%27ll%20be%20covering.%20Making%20use%20of%20div%27s%20with%20CSS.%20You%27ll%20need%20to%20" title="del.icio.us"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;t=CSS%20Lesson%206%3A%20Intro%20to%20Divs" title="Facebook"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;annotation=Alright%2C%20alright.%20So%20I%20skipped%20all%20that%20fuss%20with%20horizontal%20navbars%20but%20that%20stuff%20is%20easy%20so%20I%27ll%20create%20a%20short%20article%20on%20it%20later.%0D%0A%0D%0ALet%27s%20start%20with%20the%20%26lt%3Bdiv%26gt%3B%20tag.%20It%27s%20what%20I%27ll%20be%20covering.%20Making%20use%20of%20div%27s%20with%20CSS.%20You%27ll%20need%20to%20" title="Google Bookmarks"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;source=Dave+PC+Guy+Computers+and+Technology&amp;summary=Alright%2C%20alright.%20So%20I%20skipped%20all%20that%20fuss%20with%20horizontal%20navbars%20but%20that%20stuff%20is%20easy%20so%20I%27ll%20create%20a%20short%20article%20on%20it%20later.%0D%0A%0D%0ALet%27s%20start%20with%20the%20%26lt%3Bdiv%26gt%3B%20tag.%20It%27s%20what%20I%27ll%20be%20covering.%20Making%20use%20of%20div%27s%20with%20CSS.%20You%27ll%20need%20to%20" title="LinkedIn"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" /></a>
	<a rel="nofollow"  target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs" title="Reddit"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.tumblr.com/share?v=3&amp;u=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;t=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;s=Alright%2C%20alright.%20So%20I%20skipped%20all%20that%20fuss%20with%20horizontal%20navbars%20but%20that%20stuff%20is%20easy%20so%20I%27ll%20create%20a%20short%20article%20on%20it%20later.%0D%0A%0D%0ALet%27s%20start%20with%20the%20%26lt%3Bdiv%26gt%3B%20tag.%20It%27s%20what%20I%27ll%20be%20covering.%20Making%20use%20of%20div%27s%20with%20CSS.%20You%27ll%20need%20to%20" title="Tumblr"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/tumblr.png" title="Tumblr" alt="Tumblr" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=CSS%20Lesson%206%3A%20Intro%20to%20Divs%20-%20http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F" title="Twitter"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" /></a>
	<a rel="nofollow"  target="_blank" href="mailto:?subject=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;body=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F" title="email"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/email_link.png" title="email" alt="email" /></a>
	<a rel="nofollow"  target="_blank" href="http://slashdot.org/bookmark.pl?title=CSS%20Lesson%206%3A%20Intro%20to%20Divs&amp;url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F" title="Slashdot"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fwww.davepcguy.com%2Farchive%2Fcss-lesson-6-intro-to-divs%2F&amp;title=CSS%20Lesson%206%3A%20Intro%20to%20Divs" title="StumbleUpon"><img src="http://www.davepcguy.com/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.davepcguy.com/archive/css-lesson-6-intro-to-divs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
