<?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>A K Chauhan's Blog &#187; CSS</title>
	<atom:link href="http://www.akchauhan.com/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Mon, 02 Jan 2012 03:29:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create Simple Carousel using jQuery</title>
		<link>http://www.akchauhan.com/create-simple-carousel-using-jquery/</link>
		<comments>http://www.akchauhan.com/create-simple-carousel-using-jquery/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 03:42:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Carousel]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=607</guid>
		<description><![CDATA[You can see the working demo here. Carousel is a way to present content in the form of slideshow on web page. Here I&#8217;m showing how easily you can create a horizontal carousel using jQuery. You can play with the given code and easily create vertical carousel, circular carousel, auto-scrolling carousel etc. I&#8217;m using jQuery [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_609" class="wp-caption aligncenter" style="width: 671px"><a href="http://www.akchauhan.com/examples/carousel/" target="_blank"><img src="http://www.akchauhan.com/wp-content/uploads/2010/02/carousel.png" alt="Carousel Image" title="Carousel" width="661" height="163" class="size-full wp-image-609" /></a><p class="wp-caption-text">Carousel</p></div>
<p><strong>You can see the working demo <a href="http://www.akchauhan.com/examples/carousel/">here</a></strong>.</p>
<p><strong>Carousel </strong>is a way to present content in the form of <strong>slideshow </strong> on web page. Here I&#8217;m showing how easily you can create a horizontal carousel using <strong>jQuery</strong>. You can play with the given code and easily create <strong>vertical carousel, circular carousel, auto-scrolling carousel</strong> etc.</p>
<p>I&#8217;m using jQuery for animation. So, you need jQuery JavaScript library for it. You can download latest jQuery JavaScript library from <a href="http://jquery.com/">jquery.com</a>.</p>
<h3>So, how it work.</h3>
<p>Your basic structure of HTML for Carousel should be like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;my_carousel&quot;&gt;
   &lt;ul&gt;
    	&lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        &lt;li&gt;some content...&lt;/li&gt;
        .....
    &lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<h3>What you need to do before applying &#8220;my_carousel&#8221; ID to your Carousel DIV.</h3>
<p>1. Put any HTML content which you want to display in your <strong>LI&#8217;s</strong>.<br />
2. Create <strong>CSS </strong>for your Carousel DIV.<br />
3. You also need two images, or button to scroll your content in left and right direction.<br />
4. Assign &#8220;<strong>btnprev</strong>&#8221; class to your left button or image.<br />
5. Assign &#8220;<strong>btnnext</strong>&#8221; class to your right button or image.<br />
6. Assign &#8220;<strong>my_carousel</strong>&#8221; ID to you Carousel DIV.</p>
<h3>How JavaScript Code work:-</h3>
<p>So, when browser load the page JavaScript look for &#8220;<strong>my_carousel</strong>&#8221; ID in HTML and apply all the require attributes and events to your DIV, UL, and LI.</p>
<h4>Important JavaScript variables and their purpose:-</h4>
<p><strong>step</strong> &#8211; How many LI&#8217;s you want to scroll on click of left and right button.<br />
<strong>current</strong> &#8211; Index or Number of left most visible LI in carousel.<br />
<strong>maximum</strong> &#8211; Total number of LI in carousel.<br />
<strong>visible</strong> &#8211; Number of visible LI&#8217;s.<br />
<strong>speed</strong> &#8211; Animation speed.<br />
<strong>liSize</strong> &#8211; Width of one LI in pixels.<br />
<strong>carousel_height</strong> &#8211; Carousel DIV height.<br />
<strong>ulSize</strong> &#8211; Width of UL. You can calculate it like this liSize * maximum.<br />
<strong>divSize</strong> &#8211; Width of CArousel DIV. You can calculate it like this liSize * visible.</p>
<h3>Assign require attributes to DIV, UL, and LI.</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> divSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;height&quot;</span><span style="color: #339933;">,</span> carousel_height<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;visible&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;overflow&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> ulSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">*</span> liSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Here we changed the <strong>width, height, visibility, overflow, and position</strong> of Carousel DIV. The Carousel DIV <strong>overflow = hidden</strong> property is very important here, through it we are just showing the require(visible) LI&#8217;s which we want to show at a time. We just hide the remaining LI&#8217;s.</p>
<p>We also changes the <strong>width, left and position</strong> of UL.</p>
<h3>Assign Click event to left and right buttons/images</h3>
<h4>Left button/image</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnprev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">-</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">-</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		current <span style="color: #339933;">=</span> current <span style="color: #339933;">-</span> step<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So, we have assigned a click event on previous button. So, we are first checking the index of current LI. If the current LI is the first LI we will not do anything. We will simply return from the function. If the current LI is not the first LI then scroll the content of UL to left hand side by using the<strong> jQuery &#8220;animate&#8221; function</strong>. For more information about animate function <strong><a href="http://api.jquery.com/animate/">click here</a></strong>. And we also changed the current to current left most most visible LI.</p>
<h4>Right button/image</h4>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnnext'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">+</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">+</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		current <span style="color: #339933;">=</span> current <span style="color: #339933;">+</span> step<span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Similarly we assigned the clicked event on next button and followed the same logic what we used for previous click. We just changed it slightly to check last LI when we click on next button. If the current is last LI we will do nothing.</p>
<h3>Complete JavaScript Code:-</h3>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> step <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> current <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> maximum <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> visible <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span> 
		<span style="color: #003366; font-weight: bold;">var</span> liSize <span style="color: #339933;">=</span> <span style="color: #CC0000;">331</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> carousel_height <span style="color: #339933;">=</span> <span style="color: #CC0000;">161</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> ulSize <span style="color: #339933;">=</span> liSize <span style="color: #339933;">*</span> maximum<span style="color: #339933;">;</span>   
		<span style="color: #003366; font-weight: bold;">var</span> divSize <span style="color: #339933;">=</span> liSize <span style="color: #339933;">*</span> visible<span style="color: #339933;">;</span>  
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> ulSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">*</span> liSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;absolute&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;width&quot;</span><span style="color: #339933;">,</span> divSize<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;height&quot;</span><span style="color: #339933;">,</span> carousel_height<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;px&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;visibility&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;visible&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;overflow&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;hidden&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;position&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;relative&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnnext'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">+</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">+</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				current <span style="color: #339933;">=</span> current <span style="color: #339933;">+</span> step<span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnprev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>current <span style="color: #339933;">-</span> step <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> current <span style="color: #339933;">-</span> step <span style="color: #339933;">&gt;</span> maximum <span style="color: #339933;">-</span> visible<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				current <span style="color: #339933;">=</span> current <span style="color: #339933;">-</span> step<span style="color: #339933;">;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my_carousel ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>liSize <span style="color: #339933;">*</span> current<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-simple-carousel-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create CSS Stylesheet and JavaScript for Print</title>
		<link>http://www.akchauhan.com/create-css-stylesheet-and-javascript-for-print/</link>
		<comments>http://www.akchauhan.com/create-css-stylesheet-and-javascript-for-print/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 16:38:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Print]]></category>
		<category><![CDATA[StyleSheet]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=240</guid>
		<description><![CDATA[When we want to print out HTML page we need a lighter version of our HTML page. Basically, we don&#8217;t want to print the background images, background colors, advertisements and other things which are not relevant in printing. For this purpose, we need to specify a CSS stylesheet which browser use when we print our [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_241" class="wp-caption aligncenter" style="width: 528px"><img src="http://www.akchauhan.com/wp-content/uploads/2009/04/coupon.jpg" alt="CSS Stylesheet for Print" title="CSS Stylesheet for Print" width="518" height="263" class="size-full wp-image-241" /><p class="wp-caption-text">CSS Stylesheet for Print</p></div>
<p>When we want to print out HTML page we need a lighter version of our HTML page. Basically, we don&#8217;t want to print the background images, background colors, advertisements and other things which are not relevant in printing. For this purpose, we need to specify a CSS stylesheet which browser use when we print our HTML page. We can also change the width and layout of our HTML page. We can specify our CSS stylesheet for print like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
/*External style sheets*/
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css/print.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;print&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
/*Embedded style sheets*/
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;print&quot;</span>&gt;</span>
	.noprint
        {
		display:none;
	}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>

<p>The important thing to note here is the media descriptor <strong>media=&#8221;print&#8221;</strong> which we are giving through <strong>media</strong> attribute. The browser knows using this media descriptor that this CSS stylesheet is defined to use at the time of print. We can define CSS stylesheet for SCREEN like this.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
/*External style sheets*/
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css/style.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
/*Embedded style sheets*/
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span>
	.header
        {
		width:800px;
                height:200px;
	}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>

<p>In the following example, I don&#8217;t want to print the &#8220;<strong>Print this Coupon</strong>&#8221; link in coupon. So, I have just added the class &#8220;<strong>noprint</strong>&#8221; and set the display property none in this class. Now, I will apply this class to all the elements which I don&#8217;t want to print. You can easily create other classes for different purpose like to change the background color of element in print.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--coupon.html--&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>CSS stylesheet for Print<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css/style.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;css/print.css&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;print&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;coupon-mini&quot;</span>&gt;</span>
  	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;146&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'default-coupon'</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'/sites/default/files/coupon_116_116.'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;354&quot;</span> <span style="color: #000066;">align</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;left&quot;</span> <span style="color: #000066;">valign</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;top&quot;</span>&gt;</span>
      	  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;font-family: 'palatino linotype',palatino; line-height:18px; padding:6px 0 0 0; color:#0e549c; &quot;</span>&gt;</span>
          		Divan Restaurant and Hookah Lounge, Alabama          
          <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'coupons-text1'</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">span</span>&gt;</span>McDonald 20% Off.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>McDonald 20% Off.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear:both;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;detail-basic1&quot;</span>&gt;</span>
          	 3125 Piedmont Rd NE, Atlanta, Alabama<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span>&gt;</span> 
             <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">strong</span>&gt;</span> Phone Number :<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">strong</span>&gt;</span>  (404) 365-0410<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>
             <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">strong</span>&gt;</span> Pincode:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">strong</span>&gt;</span>  30305 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;openhr1&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">strong</span>&gt;</span> Opening Hours:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">strong</span>&gt;</span>  6:30 PM to 01:00 AM<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;web1&quot;</span>&gt;</span>
             	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lft1&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;about-web-link&quot;</span>&gt;</span>http://www.divanatlanta.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rght1&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;about-mail-link&quot;</span>&gt;</span>ajay0878@yahoo.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
      <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;print noprint&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:window.print();&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;coupon-print-link&quot;</span>&gt;</span>Print this Coupon<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>We have also added the <strong>window.print()</strong> function on Print this Coupon link. This function print the current windows content. We can also print our page through File->Print&#8230; menu. But this function is useful when the toolbar and menubar are disabled. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-css-stylesheet-and-javascript-for-print/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

