<?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>Tutorialzine &#187; MicroTuts</title>
	<atom:link href="http://tutorialzine.com/category/microtuts/feed/" rel="self" type="application/rss+xml" />
	<link>http://tutorialzine.com</link>
	<description>Web Development Tutorials &#38; Resources</description>
	<lastBuildDate>Fri, 03 Sep 2010 18:31:57 +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>MicroTut: How CSS Positioning Works</title>
		<link>http://tutorialzine.com/2010/06/microtut-how-css-position-works/</link>
		<comments>http://tutorialzine.com/2010/06/microtut-how-css-position-works/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 15:37:50 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=968</guid>
		<description><![CDATA[Undoubtedly, the position property is one of the most useful tools that designers have in their CSS toolbox. However, there are a few concepts about positioning that might baffle beginners.]]></description>
			<content:encoded><![CDATA[<p>Undoubtedly, the <em>position</em> property is one of the most useful tools that designers have in their CSS toolbox. However, there are a few concepts about positioning that might baffle beginners.</p>
<h3>First, what is positioning?</h3>
<p>When your browser opens a webpage, it starts rendering elements (divs, paragraphs, headings etc.) in the order they appear in the HTML markup of the page. Positioning is a natural way of organizing how the elements are displayed and an easy resolution to situations like overlaps. There are four types of positioning: <em>static</em>, <em>relative</em>, <em>absolute</em> and <em>fixed</em>.</p>
<h3>Elements are statically positioned by default</h3>
<p>The default positioning, which is implicitly applied to every element on the page, is <em>static</em>. Static positioning means that every element is positioned in the natural order it is added to the page. Block elements are displayed under other block elements, and inline elements are displayed next to other inline elements.</p>
<h3>Relative positioning</h3>
<p>Setting the positioning to relative does not by itself produce any noticeable difference in the way the element is displayed on the page. But you can now move it from its normal position with the <em>top</em>, <em>left</em>, <em>bottom</em> and <em>right</em> CSS properties. This comes really handy when dealing with situations in which you need to offset an element, but not anchor it to a specified position on the page.</p>
<pre class="brush:css">.relativeDiv{

	/*
		Moving the div to the top-left
		from where it would normally show:
	 */

	position:relative;
	top:-50px;
	left:-100px;
}
</pre>
<h3>Fixed positioning</h3>
<p>Adding <em>position:fixed</em> to the CSS declarations of an element, positions it in relation to the browser window. This allows you to display toolbars, buttons or navigation menus, which are anchored at a fixed position and scroll with the page.</p>
<pre class="brush:css">.fixedDiv{

	/*
		Fixing the div 20 px from the bottom
		of the browser window:
	 */

	position:fixed;
	right:20px;
	bottom:20px;
}
</pre>
<p>Probably the only drawback is that this positioning is  not supported in older browsers like IE6, if you can&#8217;t afford the luxury of dropping support for these.</p>
<h3>Absolute positioning</h3>
<p>An absolutely positioned element is displayed on the page in relation to the <strong>document</strong>, or a <strong>parent element with a positioning different from static</strong>. This way, using the <em>top</em>, <em>left</em>, <em>bottom</em> and <em>right</em> CSS  properties, you can specify an exact position. This also gives you the ability to center divs horizontally and vertically, which we discussed in the <a href="http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/" target="_blank"><em>&#8220;Centering a Div Both Horizontally And Vertically&#8221;</em> MicroTut.</a></p>
<pre class="brush:css">.parentDiv{

	/* Absolute and Fixed positioning would work as well: */

	position:relative;
}
.absoluteDiv{

	/*
		Displaying the div 50px from the right and 90px from
		the top of its parent because of the explicit positioning
	 */

	position:absolute;
	right:50px;
	top:90px;
}
</pre>
<h3>The benefits</h3>
<p>Using these positioning properties you can achieve all kinds of advanced page layouts, which will bring your designs to the next level. In conjunction with the <em>z-index</em> property, you can change the default overlay rules that apply to elements (elements which appear later in the code are shown above the previous ones).</p>
<p><strong>What is the coolest design you&#8217;ve done with the positioning properties? Brag in the comment section below.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2010/06/microtut-how-css-position-works/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>MicroTut: Getting And Setting Cookies With jQuery &amp; PHP</title>
		<link>http://tutorialzine.com/2010/03/microtut-getting-and-setting-cookies-with-jquery-php/</link>
		<comments>http://tutorialzine.com/2010/03/microtut-getting-and-setting-cookies-with-jquery-php/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 20:25:04 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=771</guid>
		<description><![CDATA[In this MicroTut we are going to take a look at how cookies are created and read in both PHP and JavaScript.]]></description>
			<content:encoded><![CDATA[<p>HTTP is a stateless protocol, which means that every request you make to a website is standalone and therefore cannot keep data by itself. But this simplicity is also one of the reasons for its widespread adoption in the early ears of the web.</p>
<p>There is, however, a way to keep information between requests in the form of cookies. This way you can have effective session managemet and persistent data.</p>
<p>There are two ways to work with cookies &#8211; server side (PHP, ASP etc) and client side (JavaScript). In this MicroTut we are going to take a look at how cookies are created and read in both PHP and JavaScript.</p>
<h3>Cookies and PHP</h3>
<h4>Setting cookies</h4>
<p>To create a cookie in PHP, you need to use the <strong>setcookie </strong>function. It takes a number of parameters (all except for the first are optional and can be omitted):</p>
<pre class="brush:php">setcookie(
	'pageVisits',				// Name of the cookie, required
	$visited,					// The value of the cookie
	time()+7*24*60*60,			// Expiration time, set for a week in the future
	'/',						// Folder path the cookie will be available for
	'demo.tutorialzine.com'		// Domain to which the cookie will be bound
);
</pre>
<p>If you pass <strong>0</strong> as an expiration time (which is the default behavior) the cookie will be lost on browse restart. The<strong> &#8220;/&#8221; </strong>parameter indicates that it will be available for all directories of the domain (you can optionally bind a cookie to a single directory with something like <strong>/admin/</strong> as a parameter).</p>
<p>There are two additional parameters that you could pass to the function, which are not given here. They are specified with a boolean value. The first one indicates that the cookie would be transferred only on a secure HTTPS connection, and the second that the cookie will not be accessible though JavaScript (introduced in PHP 5.2)</p>
<p>For most practical purposes, you would only need the first four parameters, omitting the rest.</p>
<h4>Reading cookies</h4>
<p>Reading a cookie with PHP is a lot simpler. All the cookies that were passed to the script are available in the<strong> $_COOKIE</strong> superglobal array. In our example, to read the cookie we would write the following code:</p>
<pre class="brush:php">$visits = (int)$_COOKIE['pageVisits']+1;
echo "You visited this site: ".$visits." times";
</pre>
<p>It is a good place to note, that cookies set with <strong>setcookie </strong>are available in the $_COOKIE array on the <strong>next page load</strong>, which is something you should be aware of.</p>
<h4>Deleting cookies</h4>
<p>To delete cookies, just use <strong>setcookie</strong> and give it a time in the past as an expiration date.</p>
<pre class="brush:php">setcookie(
	'pageVisits',
	$visited,
	time()-7*24*60*60,		// One week in the past. The cookie will be deleted
	'/',
	'demo.tutorialzine.com'
);
</pre>
<h3>Cookies and jQuery</h3>
<p>To use cookies with jQuery, you will need the special <a href="http://plugins.jquery.com/project/Cookie" target="_blank">Cookie plugin</a>.</p>
<h4>Setting cookies</h4>
<p>Setting cookies with the Cookie plug-in is quite intuitive:</p>
<pre class="brush:js">$(document).ready(function(){

	// Setting a kittens cookie, it will be lost on browser restart:
	$.cookie("kittens","Seven Kittens");

	// Setting demoCookie (as seen in the demonstration):
	$.cookie("demoCookie",text,{expires: 7, path: '/', domain: 'demo.tutorialzine.com'});

	// "text" is a variable holding the string to be saved
});
</pre>
<h4>Reading cookies</h4>
<p>Reading a cookie is even simpler. Just call the <strong>$.cookie()</strong> function with a single cookie-name parameter, and the value of the cookie will be returned:</p>
<pre class="brush:js">$(document).ready(function(){

	// Getting the kittens cookie:
	var str = $.cookie("kittens");

	// str now contains "Seven Kittens"
});
</pre>
<h4>Deleting cookies</h4>
<p>To delete a cookie, again use the <strong>$.cookie()</strong> function, but pass <strong>null</strong> as its second parameter.</p>
<pre class="brush:js">$(document).ready(function(){

	// Deleting the kittens cookie:
	var str = $.cookie("kittens",null);

	// No more kittens
});
</pre>
<h3>To wrap it up</h3>
<p>In this MicroTut we took a look at setting and reading cookie data. It is a good place to note that you <strong>should not store</strong> any sensitive information such as usernames or passwords in cookies, as they are transmitted as regular headers on every page load and can be easily sniffed by wrongdoers. However, with proper precautions, you can achieve a great deal of interactivity thanks to this simple technology.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2010/03/microtut-getting-and-setting-cookies-with-jquery-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>MicroTut: Centering a Div Both Horizontally And Vertically</title>
		<link>http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/</link>
		<comments>http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 17:27:57 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[MicroTuts]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=741</guid>
		<description><![CDATA[In this MicroTut, we are going to take a look at a couple of ways to center a div both horizontally and vertically with pure CSS. A jQuery method is also presented.]]></description>
			<content:encoded><![CDATA[<p>While building web page layouts, you&#8217;ve probably been faced with a situation where you need to center a div both horizontally and vertically with pure CSS. There are more than a few ways to achieve this, and in this MicroTut I am going to show you my favorite involving CSS and jQuery.</p>
<p>But first, the basics:</p>
<h3>Horizontal centering with CSS</h3>
<p>It is as easy as applying a margin to a div:</p>
<pre class="brush:css">.className{
	margin:0 auto;
	width:200px;
	height:200px;
}
</pre>
<p>To center a div only horizontally, you need to specify a width, and an <strong>auto</strong> value for the <strong>left and right margins</strong> (you do remember the shorthand declarations in CSS don&#8217;t you?). This method works on block level elements (divs, paragraphs, h1, etc). To apply it to inline elements (like hyperlinks and images), you need to apply one additional rule &#8211; <strong>display:block</strong>.</p>
<h3>Horizontal and vertical centering with CSS</h3>
<p>Center a div both horizontally and vertically with CSS is a bit more tricky. You need to know the dimensions of the div beforehand.</p>
<pre class="brush:css">.className{
	width:300px;
	height:200px;
	position:absolute;
	left:50%;
	top:50%;
	margin:-100px 0 0 -150px;
}
</pre>
<p>By positioning the element <strong>absolutely</strong>, we can detach it from its surroundings and specify its position in relation to the browser window. Offsetting the div by <strong>50%</strong> from the left and the top part of the window, you have its upper-left corner precisely at the center of the page. The only thing we are left to do is to move the div to the <strong>left</strong> and to the <strong>top</strong> with <strong>half</strong> its width and height with a negative margin, to have it perfectly centered.</p>
<h3>Horizontal and vertical centering with jQuery</h3>
<p>As mentioned earlier &#8211; the CSS method only works with divs with fixed dimensions. This is where jQuery comes into play:</p>
<pre class="brush:js">$(window).resize(function(){

	$('.className').css({
		position:'absolute',
		left: ($(window).width() - $('.className').outerWidth())/2,
		top: ($(window).height() - $('.className').outerHeight())/2
	});

});

// To initially run the function:
$(window).resize();
</pre>
<p>The functionality is inserted into a <strong>$(window).resize()</strong> statement, which is executed every time the window is resized by the user. We use <strong>outerWidth()</strong> and <strong>outerHeight()</strong>, because unlike from the regular <strong>width()</strong> and <strong>height()</strong>, they add the padding and the border width to the returned size. Lastly, we simulate a resize event to kick center the div on page load.</p>
<p>The benefit of using this method, is that you do not need to know how big the div is. The main disadvantage is that it will only work with JavaScript turned on. This however makes it perfect for rich user interfaces (such as facebook&#8217;s).</p>
<p><strong>Be sure to share your favorite methods in the comment section.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2010/03/centering-div-vertically-and-horizontally/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>MicroTut: The jQuery Hover Method</title>
		<link>http://tutorialzine.com/2010/02/the-jquery-hover-method/</link>
		<comments>http://tutorialzine.com/2010/02/the-jquery-hover-method/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 20:23:43 +0000</pubDate>
		<dc:creator>Martin Angelov</dc:creator>
				<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://tutorialzine.com/?p=732</guid>
		<description><![CDATA[When building a navigation menu, or any other jQuery script, it is often necessary to have a robust method with which to define a mouse over and mouse out state. This is where the hover() method comes along.]]></description>
			<content:encoded><![CDATA[<p>When building a navigation menu, or any other jQuery script, it is often necessary to have a robust method with which to define a mouse over and mouse out state. This is where the <strong>hover()</strong> method comes along. Here is how it is used:</p>
<pre class="brush:js">$('.selectorClass').hover(
function(){
	$(this).stop().fadeTo('slow',0.4);
},
function(){
	$(this).stop().fadeTo('slow',1);
});
</pre>
<p>This assigns the first function to be executed when the mouse moves above the elements on the page, which share the <strong>selectorClass</strong> class name, and the second one is executed when the mouse moves away.</p>
<p>You can use &#8220;<strong>this&#8221;</strong> inside of the functions, to access the element that triggered the event.</p>
<p>Hover actually binds the first function to the <strong>mouseenter</strong> event, and the second one to <strong>mouseleave</strong>, so you could alternatively write this:</p>
<pre class="brush:js">$('.selectorClass').mouseenter(function(){
	$(this).stop().fadeTo('slow',0.4);
}).mouseleave(function(){
	$(this).stop().fadeTo('slow',1);
});
</pre>
<p>As of <strong>version 1.4</strong> of jQuery, it is now possible to pass a single function to hover, which will be called on both mouseenter and mouseleave. This way you can shorten your code even more by writing only one function:</p>
<pre class="brush:js">$('.selectorClass').hover(function(){
	this.check = this.check || 1;
	$(this).stop().fadeTo('slow',this.check++%2==0 ? 1 : 0.4);
});
</pre>
<p>The example above increments <strong>this.check</strong> every time the function is run. Depending on whether the number is even or not, it chooses the opacity level to pass to <strong>fadeTo()</strong> (1 being completely visible).</p>
<p>This is also a great place to use the jQuery toggle functions like <strong>.slideToggle()</strong> and <strong>.toggleClass()</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://tutorialzine.com/2010/02/the-jquery-hover-method/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Content Delivery Network via cdn.tutorialzine.com

Served from: tutorialzine.com @ 2010-09-08 23:23:19 -->