<?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>ViralPatel.net &#187; CSS</title> <atom:link href="http://viralpatel.net/blogs/category/css/feed" rel="self" type="application/rss+xml" /><link>http://viralpatel.net/blogs</link> <description>Tutorials, Java, J2EE, Struts, AJAX, JavaScript, CSS, Web 2.0, MySQL, Articles</description> <lastBuildDate>Tue, 24 Jan 2012 13:45: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>Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</title><link>http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html</link> <comments>http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html#comments</comments> <pubDate>Tue, 28 Dec 2010 12:40:07 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JQuery]]></category> <category><![CDATA[How-To]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=2126</guid> <description><![CDATA[Facebook user updates has a great functionality. If the comment text is larger than few characters, the extra words are hide and a show more link is presented to user. This way you can keep long text out of the view to user and stop the cluttering of page. Also interested users can click on [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2010/12/show-more-link.png" alt="" title="show-more-link" width="341" height="82" class="aligncenter size-full wp-image-2127" /><br /> Facebook user updates has a great functionality. If the comment text is larger than few characters, the extra words are hide and a show more link is presented to user. This way you can keep long text out of the view to user and stop the cluttering of page. Also interested users can click on <em>more</em> link and see the full content.</p><p>Here is a simple tutorial to achieve this using jQuery / Javascript.</p><h2>The HTML</h2><p>Below is the sample text. Each text is wrapped in a DIV tag. Note that we have added a class &#8220;more&#8221; in each div. This class will decide if a text needs to be shortened and show more link showed or not.</p><pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;comment more&quot;&gt;
	Lorem ipsum dolor sit amet, consectetur adipiscing elit.
	Vestibulum laoreet, nunc eget laoreet sagittis,
	quam ligula sodales orci, congue imperdiet eros tortor ac lectus.
	Duis eget nisl orci. Aliquam mattis purus non mauris
	blandit id luctus felis convallis.
	Integer varius egestas vestibulum.
	Nullam a dolor arcu, ac tempor elit. Donec.
&lt;/div&gt;
&lt;div class=&quot;comment more&quot;&gt;
	Duis nisl nibh, egestas at fermentum at, viverra et purus.
	Maecenas lobortis odio id sapien facilisis elementum.
	Curabitur et magna justo, et gravida augue.
	Sed tristique pellentesque arcu quis tempor.
&lt;/div&gt;
&lt;div class=&quot;comment more&quot;&gt;
	consectetur adipiscing elit. Proin blandit nunc sed sem dictum id feugiat quam blandit.
	Donec nec sem sed arcu interdum commodo ac ac diam. Donec consequat semper rutrum.
	Vestibulum et mauris elit. Vestibulum mauris lacus, ultricies.
&lt;/div&gt;
</pre><h2>The CSS</h2><p>Below is the CSS code for our example. Note the class &#8220;.morecontent span&#8221; is hidden. The extra text from the content is wrapped in this span and is hidden at time of page loading.</p><pre class="brush: css; title: ; notranslate">
a {
	color: #0254EB
}
a:visited {
	color: #0254EB
}
a.morelink {
	text-decoration:none;
	outline: none;
}
.morecontent span {
	display: none;
}
.comment {
	width: 400px;
	background-color: #f0f0f0;
	margin: 10px;
}
</pre><h2>The Javascript</h2><p>Below is the Javascript code which iterate through each DIV tags with class &#8220;more&#8221; and split the text in two. First half is showed to user and second is made hidden with a link &#8220;more..&#8221;.</p><p>You can change the behaviour by changing following js variables.</p><ul><li><em>showChar</em>: Total characters to show to user. If the content is more then showChar, it will be split into two halves and first one will be showed to user.</li><li><em>ellipsestext</em>: The text displayed before &#8220;more&#8221; link. Default is &#8220;&#8230;&#8221;</li><li><em>moretext</em>: The text shown in more link. Default is &#8220;more&#8221;. You can change to &#8220;>>&#8221;</li><li><em>lesstext</em>: The text shown in less link. Default is &#8220;less&#8221;. You can change to &#8220;<<"</li></ul><pre class="brush: jscript; title: ; notranslate">
$(document).ready(function() {
	var showChar = 100;
	var ellipsestext = &quot;...&quot;;
	var moretext = &quot;more&quot;;
	var lesstext = &quot;less&quot;;
	$('.more').each(function() {
		var content = $(this).html();

		if(content.length &gt; showChar) {

			var c = content.substr(0, showChar);
			var h = content.substr(showChar-1, content.length - showChar);

			var html = c + '&lt;span class=&quot;moreellipses&quot;&gt;' + ellipsestext+ '&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;morecontent&quot;&gt;&lt;span&gt;' + h + '&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;&quot; class=&quot;morelink&quot;&gt;' + moretext + '&lt;/a&gt;&lt;/span&gt;';

			$(this).html(html);
		}

	});

	$(&quot;.morelink&quot;).click(function(){
		if($(this).hasClass(&quot;less&quot;)) {
			$(this).removeClass(&quot;less&quot;);
			$(this).html(moretext);
		} else {
			$(this).addClass(&quot;less&quot;);
			$(this).html(lesstext);
		}
		$(this).parent().prev().toggle();
		$(this).prev().toggle();
		return false;
	});
});
</pre><h2>Online Demo</h2><p><a target="_blank" href="http://viralpatel.net/blogs/demo/jquery/show-more-link-shortened-content/">Click here to view demo</a><br /> <iframe src="http://viralpatel.net/blogs/demo/jquery/show-more-link-shortened-content/demo.html" width="100%" height="200px" ></iframe></p><h2>Download Source Code</h2><p><a href="http://viralpatel.net/blogs/demo/jquery/show-more-link-shortened-content/download.zip">Click here to download (ZIP, 2KB)</a></p><p><strong>Update:</strong><br /> The above code is modified into jQuery plugin. Thanks to Jay. Following is the code.</p><h2>jQuery Plugin</h2><h3>Code</h3><pre class="brush: jscript; title: ; notranslate">
jQuery.fn.shorten = function(settings) {
  var config = {
    showChars : 100,
    ellipsesText : &quot;...&quot;,
    moreText : &quot;more&quot;,
    lessText : &quot;less&quot;
  };

  if (settings) {
    $.extend(config, settings);
  }

  $('.morelink').live('click', function() {
    var $this = $(this);
    if ($this.hasClass('less')) {
      $this.removeClass('less');
      $this.html(config.moreText);
    } else {
      $this.addClass('less');
      $this.html(config.lessText);
    }
    $this.parent().prev().toggle();
    $this.prev().toggle();
    return false;
  });

  return this.each(function() {
    var $this = $(this);

    var content = $this.html();
    if (content.length &gt; config.showChars) {
      var c = content.substr(0, config.showChars);
      var h = content.substr(config.showChars , content.length - config.showChars);
      var html = c + '&lt;span class=&quot;moreellipses&quot;&gt;' + config.ellipsesText + '&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;morecontent&quot;&gt;&lt;span&gt;' + h + '&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;javascript://nop/&quot; class=&quot;morelink&quot;&gt;' + config.moreText + '&lt;/a&gt;&lt;/span&gt;';
      $this.html(html);
      $(&quot;.morecontent span&quot;).hide();
    }
  });
}</pre><h3>Download</h3><p><a target="_blank" href="http://viralpatel.net/blogs/demo/jquery/jquery.shorten.1.0.js">Click to login jQuery Shorten plugin</a></p><h3>Usage</h3><p><strong>Step 1:</strong> Include the jQuery plugin in your HTML</p><pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;
	src=&quot;http://viralpatel.net/blogs/demo/jquery/jquery.shorten.1.0.js&quot;&gt;&lt;/script&gt;
</pre><p><strong>Step 2:</strong> Add the code to shorten any DIV content. In below example we are shortening DIV with class &#8220;comment&#8221;.</p><pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;comment&quot;&gt;
	This is a long comment text.
	This is a long comment text.
	This is a long comment text.
	This is a long comment text. This is a long comment text.
&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	$(document).ready(function() {

		$(&quot;.comment&quot;).shorten();

	});
&lt;/script&gt;
</pre><p>You may want to pass the parameters to shorten() method and override the default ones.</p><pre class="brush: jscript; title: ; notranslate">
$(&quot;.comment&quot;).shorten({
	&quot;showChars&quot; : 200
});

$(&quot;.comment&quot;).shorten({
	&quot;showChars&quot; : 150,
	&quot;moreText&quot;	: &quot;See More&quot;,
});

$(&quot;.comment&quot;).shorten({
	&quot;showChars&quot; : 50,
	&quot;moreText&quot;	: &quot;See More&quot;,
	&quot;lessText&quot;	: &quot;Less&quot;,
});
</pre><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2011/02/jquery-get-text-element-without-child-element.html" title="jQuery: Get the Text of Element without Child Element">jQuery: Get the Text of Element without Child Element</a></li><li><a href="http://viralpatel.net/blogs/2010/11/multiple-checkbox-select-deselect-jquery-tutorial-example.html" title="Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example">Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/01/jquery-resizable-draggable-resize-drag-tutorial-example.html" title="jQuery Resizable and Draggable Tutorial with Example">jQuery Resizable and Draggable Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/01/fadein-fadeout-fade-out-effect-in-html-text-div-using-jquery.html" title="FadeIn FadeOut html text div effect using jQuery.">FadeIn FadeOut html text div effect using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2008/12/creating-orkut-style-status-update-div-textbox-using-jquery.html" title="Creating orkut style status update div-textbox using jQuery.">Creating orkut style status update div-textbox using jQuery.</a></li><li><a href="http://viralpatel.net/blogs/2008/11/textbox-with-background-image-using-css.html" title="Textbox with background image using CSS">Textbox with background image using CSS</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html/feed</wfw:commentRss> <slash:comments>16</slash:comments> </item> <item><title>Firefox 3.6 Released: With New CSS Gradient Feature</title><link>http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html</link> <comments>http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html#comments</comments> <pubDate>Thu, 21 Jan 2010 17:58:17 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[News]]></category> <category><![CDATA[css gradient]]></category> <category><![CDATA[Firefox]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=2004</guid> <description><![CDATA[Mozilla has finally released Firefox 3.6, the newest version of its popular browser after months of testing. New Firefox is 20% faster than Firefox 3.5, according to Mozilla. It uses Gecko 1.9.2 web-rendering, which improves its load times, startup speed and stability. Javascript execution is faster and smoother as well. There’s also autocomplete form functionality [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/07/firefox-logo.jpg" alt="firefox-logo" title="firefox-logo" width="148" height="143" class="alignright size-full wp-image-1508" />Mozilla has finally released Firefox 3.6, the newest version of its popular browser after months of testing. New Firefox is 20% faster than Firefox 3.5, according to Mozilla. It uses Gecko 1.9.2 web-rendering, which improves its load times, startup speed and stability. Javascript execution is faster and smoother as well. There’s also autocomplete form functionality and full HTML5 support. New feature called Personas has been added in Firefox 3.6 which lets you customize your Firefox with a single click and without a restart.</p><p>My Favourite feature is the addition of new CSS Gradient API. You can define Gradient effect on any element by specifying simple CSS styles. Thus now you can have CSS Gradient Effect without Images!<br /> <strong>Note:</strong> All the below examples are Images. In order to view the gradient effect one must use Firefox 3.6</p><h2>Liner Gradient</h2><p>To create a linear gradient, you’ll need to set a starting point and a direction (or angle) for the gradient and to define the color stops.</p><pre class="brush: css; title: ; notranslate">
-moz-linear-gradient( [&lt;point&gt; || &lt;angle&gt;,]? &lt;stop&gt;, &lt;stop&gt; [, &lt;stop&gt;]* )
</pre><p><strong>Starting Point</strong>: The starting point works just like background position. You can set the horizontal and the vertical positions as a percentage, in pixels, or using left/center/right for horizontal, and top/center/bottom for vertical. Positions start from the top left corner. If you don’t specify the horizontal or the vertical position, it will default to center.<br /> <strong>Example</strong></p><pre class="brush: css; title: ; notranslate">
 .linear_gradient_square {
    width: 100px;
    height: 100px;
    border: 1px solid #333;
    background: -moz-linear-gradient(top, blue, white);
  }
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/basic_linear_bluetop.png" class="aligncenter" width="116" height="116" /></p><p>One that starts left (horizontal) and center (vertical):</p><pre class="brush: css; title: ; notranslate">
background: -moz-linear-gradient(left, blue, white);
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/basic_linear_blueleft.png" class="aligncenter" width="111" height="111" /></p><p>Here’s a simple example with three color stops. Because no point is specified for the first and last colors, they will default to 0% and 100%.</p><pre class="brush: css; title: ; notranslate">
    background: -moz-linear-gradient(top, blue, white 80%, orange);
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/linear_colorstops1.png" class="aligncenter" width="108" height="112" /></p><p>Colors will be evenly spaced if no position is specified.</p><pre class="brush: css; title: ; notranslate">
    background: -moz-linear-gradient(left, red, orange, yellow, green, blue);
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/linear_rainbow.png" class="aligncenter" width="113" height="116" /></p><h2>Radial Gradients</h2><p>The syntax for radial gradients is very similar to that of linear gradients:</p><pre class="brush: css; title: ; notranslate">
 -moz-radial-gradient([&lt;bg-position&gt; || &lt;angle&gt;,]? [&lt;shape&gt; || &lt;size&gt;,]? &lt;color-stop&gt;, &lt;color-stop&gt;[, &lt;color-stop&gt;]*);
</pre><p><strong>Color stops</strong>: Just like with linear gradients, you should define color stops along the gradient line. The following circles have the same color stops, but the gradient on the left defaults to evenly spaced colors, while the one on the right has a specific position for each color.</p><pre class="brush: css; title: ; notranslate">
background: -moz-radial-gradient(red, yellow, #1E90FF);
background: -moz-radial-gradient(red 5%, yellow 25%, #1E90FF 50%);
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/radial_gradient_stop.png" class="aligncenter" width="243" height="115" /></p><pre class="brush: css; title: ; notranslate">
.radial_gradient_circle {
    background: -moz-radial-gradient(bottom left, circle, red, yellow, #1E90FF);
}
 .radial_gradient_ellipse {
    background: -moz-radial-gradient(bottom left, ellipse, red, yellow, #1E90FF);
}</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/radial_circle_ellipse.png" class="aligncenter" width="544" height="116" /></p><pre class="brush: css; title: ; notranslate">
background: -moz-radial-gradient(ellipse closest-side, red, yellow 10%, #1E90FF 50%, white);
background: -moz-radial-gradient(ellipse farthest-corner, red, yellow 10%, #1E90FF 50%, white);
</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/radial_ellipse_size.png" class="aligncenter" width="549" height="123" /></p><pre class="brush: css; title: ; notranslate">
.repeating_radial_gradient_example {
    background: -moz-repeating-radial-gradient(black, black 5px, white 5px, white 10px);
}
 .repeating_linear_gradient_example {
     background: -moz-repeating-linear-gradient(top left -45deg, red, red 5px, white 5px, white 10px);
}</pre><p><img alt="" src="http://hacks.mozilla.org/wp-content/uploads/2009/11/repeating_gradients.png" class="aligncenter" width="257" height="117" /></p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html" title="20 Very Useful CSS Stylesheet Tips &#038; Tricks">20 Very Useful CSS Stylesheet Tips &#038; Tricks</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html" title="Rounded corner CSS without images">Rounded corner CSS without images</a></li><li><a href="http://viralpatel.net/blogs/2009/07/firefox-35-critical-javascript-vulnerability.html" title="Firefox 3.5 has a critical JavaScript vulnerability">Firefox 3.5 has a critical JavaScript vulnerability</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>20 Very Useful CSS Stylesheet Tips &amp; Tricks</title><link>http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html</link> <comments>http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html#comments</comments> <pubDate>Fri, 06 Nov 2009 04:00:02 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[Featured]]></category> <category><![CDATA[tips & tricks]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1895</guid> <description><![CDATA[Following are few CSS Tips and Tricks that I think every web developer should be aware of. You may already know many of these tricks. Disclaimer: Not all from the below CSS tricks are written by me. Some of them are taken from different sources on internet. 1. Round Corners without images Here is a [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/11/css-example-pic.jpg" alt="css-example-pic" title="css-example-pic" width="441" height="272" class="aligncenter size-full wp-image-1896" /><br /> Following are few CSS Tips and Tricks that I think every web developer should be aware of. You may already know many of these tricks.<br /> Disclaimer: Not all from the below CSS tricks are written by me. Some of them are taken from different sources on internet.</p><h2>1. Round Corners without images</h2><p>Here is a simple CSS technique of rounding off the corners of the DIV using some css attributes. This technique will work in Firefox, Safari, Chrome and any other CSS3-compatible browser. This technique will not work in Internet Explorer.</p><pre class="brush: css; title: ; notranslate">
div {
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	border-radius: 10px;
}
</pre><p>To round a specific corner (top-left or bottom-right) use below stylesheet.</p><pre class="brush: css; title: ; notranslate">
div {
	-moz-border-radius-topleft: 10px;
	-webkit-border-top-left-radius: 10px;
}
</pre><p><strong>Further Reading:</strong> <a target="_new" href="http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html">Rounded Corner Stylesheet without images</a></p><h2>2. Create an IE Specific Stylesheet</h2><p>Create a separate stylesheet altogether and include it in the webpage whenever the client is using Internet Explorer.<br /> <b>IE Only</b></p><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie-only.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><p><b>IE 7 Only</b></p><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 7]&gt;
	&lt;link href=&quot;IE-7-SPECIFIC.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
&lt;![endif]--&gt;
</pre><p><strong>Further Reading:</strong> <a target="_new" href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html">IE Specific Stylesheet</a></p><h2>3. Background Image of Textbox</h2><p>Have you seen textboxes with background images like Search magnify glass or other images? Simply use following stylesheet to add background image to any input box.</p><pre class="brush: css; title: ; notranslate">
input#sometextbox {
	background-image:url('back-image.gif');
	background-repeat:no-repeat;
	padding-left:20px;
}
</pre><p><strong>Further Reading:</strong> <a target="_new" href="http://viralpatel.net/blogs/2008/11/textbox-with-background-image-using-css.html">Background Image for Textbox</a></p><h2>4. Setting Minimum width for a page</h2><p>A very handy CSS command that exists is the min-width command, whereby you can specify a minimum width for any element. This can be particularly useful for specifying a minimum width for a page.</p><pre class="brush: xml; title: ; notranslate">
 &lt;body&gt;
&lt;div id=&quot;container&quot;&gt;
</pre><p>Next we create our CSS commands, so as to create a minimum width of 600px:</p><pre class="brush: css; title: ; notranslate">
#container {
	min-width: 600px;
	width:expression(document.body.clientWidth &lt; 600? &quot;600px&quot;: &quot;auto&quot; );
}
</pre><p>The first command is the regular minimum width command; the second is a short JavaScript command that only IE understands. Do note though, this command will cause your CSS document to invalidate so you may prefer to insert it into the head of each HTML document to get round this.</p><h2>5. Cross Browser Opacity</h2><p>Use following stylesheet to make an element transperant by setting the opacity level.</p><pre class="brush: css; title: ; notranslate">
.transparent_class {
	filter:alpha(opacity=50);
	-moz-opacity:0.5;
	-khtml-opacity: 0.5;
	opacity: 0.5;
}
</pre><h2>6. Prevent Firefox Scrollbar Jump</h2><p>Firefox does not display scroll bar if the content of page is fitting with browser height. But if the content grows, Firefox display a scroll bar their by making a scroll jump. The content of screen will be pushed left. To avoid this we can tell firefox to add scroll bar by default.</p><pre class="brush: css; title: ; notranslate">
	html		{ overflow-y:scroll; }
</pre><h2>7. Rotate Text using CSS</h2><p>This example rotates text 90 degrees counterclockwise.</p><p>The rotation property of Internet Explorer’s BasicImage filter can accept one of four values: 0, 1, 2, or 3 which will rotate the element 0, 90, 180 or 270 degress respectively.</p><pre class="brush: css; title: ; notranslate">
.rotate-style {
		/* Safari */
		-webkit-transform: rotate(-90deg);

		/* Firefox */
		-moz-transform: rotate(-90deg);

		/* Internet Explorer */
		filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
</pre><h2>8. CSS for Handheld/Mobile devices</h2><p>A separate CSS document can be created for PDAs and mobile phones, and only activated when one of these devices is being used to access your site. More and more websites are creating separate CSS documents for printing, so web pages automatically become print-friendly when users choose to print them. You can also do the same for handheld devices.<br /> The following command is used to call up the CSS document for handhelds:</p><pre class="brush: css; title: ; notranslate">
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;handheldstyle.css&quot; media=&quot;handheld&quot; /&gt;
</pre><h2>9. Change Text Selection Color</h2><p>By default, browsers uses blue color as the text selection. You can change this color to match your website theme.</p><pre class="brush: css; title: ; notranslate">
/* Mozilla based browsers */
::-moz-selection {
       background-color: #FFA;
       color: #000;
}

/* Works in Safari */
::selection {
       background-color: #FFA;
       color: #000;
}
</pre><h2>10. Remove Dotted Link Borders</h2><p>Dotted borders around links are an accessibility feature most browsers have by default. It’s for users who must or choose to navigate by keyboard, there is a visual style applied to those links when “tabbed” to. These borders also show up when the link is clicked (in it’s “active” state), and can be an eyesore depending on the design (especially when using something like CSS image replacement, the borders span the length of the screen). You can remove them with this:</p><pre class="brush: css; title: ; notranslate">
a:active {
	outline: none;
}
</pre><h2>11. Centering a Website</h2><p>Most of website uses this technique to center the content.</p><pre class="brush: xml; title: ; notranslate">
&lt;body&gt;
  &lt;div id=&quot;page-wrap&quot;&gt;
    &lt;!-- all websites HTML here --&gt;
  &lt;/div&gt;
&lt;/body&gt;
</pre><pre class="brush: css; title: ; notranslate">
#page-wrap {
     width: 800px;
     margin: 0 auto;
}
</pre><h2>12. CSS Drop Caps</h2><p>This paragraph has the class &#8220;introduction&#8221;. If your browser supports the pseudo-class &#8220;first-letter&#8221;, the first letter will be a drop-cap.</p><pre class="brush: css; title: ; notranslate">
p:first-letter {
       font-size : 300%;
       font-weight : bold;
       float : left;
       width : 1em;
}
</pre><h2>13. Attribute-Specific Icons</h2><p>CSS Attribute selectors are very powerful giving you many options to control styles of different elements e.g. you can add an icon based on the href attribute of the a tag to let the user know whether link points to an image, pdf, doc file etc.</p><pre class="brush: css; title: ; notranslate">
    a[href$='.doc'] {
        padding:0 20px 0 0;
        background:transparent url(/graphics/icons/doc.gif) no-repeat center rightright;
    }
</pre><h2>14. Capitalize Text</h2><p>This trick is especially useful for displaying title of an article on a web page with all its words starting with capital letter.</p><pre class="brush: css; title: ; notranslate">
text-transform: capitalize;  

text-transform: lowercase

text-transform: uppercase
</pre><ul><li>none:  	No capitalization. The text renders as it is. This is default</li><li>capitalize: 	Transforms the first character of each word to uppercase</li><li>uppercase: 	Transforms all characters to uppercase</li><li>lowercase: 	Transforms all characters to lowercase</li><li>inherit: 	Specifies that the value of the text-transform property should be inherited from the parent element</li></ul><h2>15. CSS Text Shadow</h2><p>Regular text shadow:</p><pre class="brush: css; title: ; notranslate">
p { text-shadow: 1px 1px 1px #000; }
</pre><p>Multiple shadows:</p><pre class="brush: css; title: ; notranslate">
p { text-shadow: 1px 1px 1px #000, 3px 3px 5px blue; }
</pre><p>The first two values specify the length of the shadow offset. The first value specifies the horizontal distance and the second specifies the vertical distance of the shadow. The third value specifies the blur radius and the last value describes the color of the shadow:</p><p>1. value = The X-coordinate<br /> 2. value = The Y-coordinate<br /> 3. value = The blur radius<br /> 4. value = The color of the shadow</p><p>Using positive numbers as the first two values ends up with placing the shadow to the right of the text horizontally (first value) and placing the shadow below the text vertically (second value).</p><p>The third value, the blur radius, is an optional value which can be specified but don’t have to. It’s the amount of pixels the text is stretched which causes a blur effect. If you don’t use the third value it is treated as if you specified a blur radius of zero.</p><h2>16. Using !important</h2><p>Experienced CSS programmers are usually aware of this but beginners do miss out on this !important CSS rule. By adding !important to your CSS rule, you can increase its precedence over other subsequent rules. e.g. in below code, background-color will be blue and not red due to !important.</p><pre class="brush: css; title: ; notranslate">
.page { background-color:blue !important;   background-color:red; }
</pre><h2>17. Print Page Breaks</h2><p>While most of the internet users prefer to read content online but some of your users might like to print your article. With CSS you can control the page breaks within content just add this CSS class to your stylesheet and add this class to any tag which you would like to print on next page.</p><pre class="brush: css; title: ; notranslate">
.page-break        { page-break-before:always; }
</pre><h2>18. CSS Pointer Cursors</h2><p>This trend has caught up lately. All user interface elements on a web page that can be clicked by user have their cursor similar to that of hyperlink. Here’s the CSS trick to do that.</p><pre class="brush: css; title: ; notranslate">
input[type=submit],label,select,.pointer { cursor:pointer; }
</pre><h2>19. Set a Consistent Base Font Size</h2><p>Setting the font-size property to 62.5% in body tag makes 1em equal to 10px. This lets you use em easily as you can find out the font-size in pixels from em values.</p><pre class="brush: css; title: ; notranslate">
body{ font-size:62.5%; }
</pre><h2>20. Perfect Page-Printing with CSS</h2><p>An overlooked feature on the website is the &#8220;print this article&#8221; link. There are many people who use the Internet who still like to print out useful articles and store them in paper form. In order to pull this off, you need to use CSS/XHTML page breaks.</p><pre class="brush: css; title: ; notranslate">
    @media all
    {
           .page-break    { display:none; }
    }  

    @media print
    {
           .page-break    { display:block; page-break-before:always; }
    }
</pre><p><strong>Further Reading:</strong><br /> <a target="_new" href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html">20 Top jQuery tips &#038; tricks for jQuery programmers</a><br /> <a target="_new" href="http://viralpatel.net/blogs/2009/05/20-useful-java-code-snippets-for-java-developers.html">20 very useful Java code snippets for Java Developers</a><br /> <a target="_new" href="http://viralpatel.net/blogs/2009/05/15-very-useful-php-code-snippets-for-php-developers.html">15 very useful PHP code snippets for PHP developers</a></p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2009/08/20-top-jquery-tips-tricks-for-jquery-programmers.html" title="20 Top jQuery Tips &#038; Tricks for jQuery Programmers">20 Top jQuery Tips &#038; Tricks for jQuery Programmers</a></li><li><a href="http://viralpatel.net/blogs/2009/08/turn-off-wordpress-image-thumbnails.html" title="Save Webserver Space by turning off Image Thumbnails in Wordpress">Save Webserver Space by turning off Image Thumbnails in Wordpress</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html/feed</wfw:commentRss> <slash:comments>13</slash:comments> </item> <item><title>Changing Form Input (Textbox) Style on Focus using jQuery</title><link>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html</link> <comments>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html#comments</comments> <pubDate>Wed, 16 Sep 2009 13:35:57 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[JQuery]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1774</guid> <description><![CDATA[User experience has always been a factor to be consider while you design a website. Lot of fields such as Human Computer Interface (HCI) and Usability etc have been studied upon. While designing a user interface, special care should always been taken while placing the text fields and selecting fonts. While lot of web designers [...]]]></description> <content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-1775" title="form-element-style-javascript-textbox" src="http://img.viralpatel.net/2009/09/form-element-style-javascript-textbox.png" alt="form-element-style-javascript-textbox" width="538" height="129" />User experience has always been a factor to be consider while you design a website. Lot of fields such as Human Computer Interface (HCI) and Usability etc have been studied upon. While designing a user interface, special care should always been taken while placing the text fields and selecting fonts. While lot of web designers prefer to display forms in plain vanilla manner, lot of others prefer to give user as much help while filling the forms. Thus the html forms should always have description field with each input field. Also if we can highlight the field that user is filling, it can improve the user experience.</p><p>Thus How can we implement the feature where the Input fields which are currently focused are highlighted?</p><p>Let us use jQuery and create a simple feature on a HTML Form.</p><h2>Step 1: The HTML Code</h2><p>We will use following form as a sample HTML Form and apply the Focus effect using jQuery.</p><pre class="brush: xml; title: ; notranslate">
&lt;FORM id=&quot;sample&quot;&gt;
	&lt;TABLE&gt;
	&lt;TR&gt;
		&lt;TD&gt;Name &lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
	&lt;TR&gt;
		&lt;TD&gt;Age&lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
	&lt;TR&gt;
		&lt;TD&gt;Phone no.&lt;/TD&gt;
		&lt;TD&gt;&lt;INPUT type=&quot;text&quot;/&gt;&lt;/TD&gt;
	&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/FORM&gt;
</pre><h2>Step 2: The CSS Stylesheet</h2><p>We will use a simple style class to apply to the focused field.</p><pre class="brush: css; title: ; notranslate">
.focus {
	border: 2px solid #AA88FF;
	background-color: #FFEEAA;
}
</pre><h2>Step 3: Add the effect using jQuery</h2><p>We will use jQuery to add effect to the form elements. Two events has to be taken care of. While the input field is focused and while the focus is moved to next textbox (blured).</p><pre class="brush: jscript; title: ; notranslate">
$('input[type=&quot;text&quot;]').focus(function() {
	$(this).addClass(&quot;focus&quot;);
});

$('input[type=&quot;text&quot;]').blur(function() {
	$(this).removeClass(&quot;focus&quot;);
});
</pre><h2>Online Demo</h2><p><iframe src="http://viralpatel.net/blogs/demo/jquery-form-input-textbox-style-focus/article-demo.html" height="150px"></iframe><br /> <a href="http://viralpatel.net/blogs/demo/jquery-form-input-textbox-style-focus/"><strong>View Demo</strong></a></p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2012/01/scroll-fix-header-jquery-facebook.html" title="Facebook Style Scroll Fixed Header in JQuery">Facebook Style Scroll Fixed Header in JQuery</a></li><li><a href="http://viralpatel.net/blogs/2011/02/clearable-textbox-jquery.html" title="Create a Clearable TextBox with jQuery">Create a Clearable TextBox with jQuery</a></li><li><a href="http://viralpatel.net/blogs/2011/02/jquery-get-text-element-without-child-element.html" title="jQuery: Get the Text of Element without Child Element">jQuery: Get the Text of Element without Child Element</a></li><li><a href="http://viralpatel.net/blogs/2011/01/first-play-framework-gae-siena-application-tutorial-example.html" title="Your first Play! &#8211; GAE &#8211; Siena application: Tutorial with Example">Your first Play! &#8211; GAE &#8211; Siena application: Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/12/jquery-ajax-handling-unauthenticated-request-ajax.html" title="jQuery Ajax &#8211; Handling unauthenticated requests via Ajax">jQuery Ajax &#8211; Handling unauthenticated requests via Ajax</a></li><li><a href="http://viralpatel.net/blogs/2010/11/multiple-checkbox-select-deselect-jquery-tutorial-example.html" title="Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example">Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Setting Height of Selectbox (Combobox) in IE</title><link>http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html</link> <comments>http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html#comments</comments> <pubDate>Fri, 11 Sep 2009 09:01:14 +0000</pubDate> <dc:creator>Gaurav Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[internet explorer]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1763</guid> <description><![CDATA[Working with Internet Explorer and creating web pages that behaves same in IE has always been frustrating for many web developers. One way of tackling IE problem is to create IE-Specific Stylesheet and thus it helps in avoiding breaking of design in IE. While working on one of the requirement I had to set height [...]]]></description> <content:encoded><![CDATA[<p>Working with Internet Explorer and creating web pages that behaves same in IE has always been frustrating for many web developers. One way of tackling IE problem is to create <a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html">IE-Specific Stylesheet</a> and thus it helps in avoiding breaking of design in IE.</p><p>While working on one of the requirement I had to set height of selectboxes on the webpage. Normally for setting up height of any html component we apply stylesheet. For example:</p><pre class="brush: css; title: ; notranslate">
select {
	height: 50px;
}
</pre><p>The above technique work for most of the browsers except Internet Explorer. The combo box does not take the height specified in CSS and is displayed with the default height only.</p><p>I tried searching Internet to see if there are some IE Specific Hacks to increase the height of the listbox. But I couldn&#8217;t find a useful fix.</p><p>Finally I end up using a workaround of fixing height issue of selectbox in IE. Just increase font size of the select box and that will increase size of it.</p><pre class="brush: css; title: ; notranslate">
select {
	font-size: 15px;
}
</pre><p>The above workaround is working for me. If you find any other useful trick for this problem please share it by comment on this article.</p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li><li><a href="http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html" title="20 Very Useful CSS Stylesheet Tips &#038; Tricks">20 Very Useful CSS Stylesheet Tips &#038; Tricks</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html" title="Rounded corner CSS without images">Rounded corner CSS without images</a></li><li><a href="http://viralpatel.net/blogs/2009/05/html-5-the-new-html-kid-on-the-block.html" title="HTML 5: The new HTML kid on the block!">HTML 5: The new HTML kid on the block!</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html/feed</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>How To: Create an IE Specific Stylesheet</title><link>http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html</link> <comments>http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html#comments</comments> <pubDate>Thu, 10 Sep 2009 07:35:12 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[hacked]]></category> <category><![CDATA[internet explorer]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1759</guid> <description><![CDATA[If you are a web developer you know how painful is to write a webpage that behaves same in all the web browsers. Generally the webpage created for Firefox behaves pretty much the same in Chrome, but Internet Explorer has its own problems. Whether it be problem with Multiple Selection in IE or the AJAX [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/09/ie-logo.jpg" alt="ie-logo" title="ie-logo" width="183" height="180" class="alignleft size-full wp-image-1760"/>If you are a web developer you know how painful is to write a webpage that behaves same in all the web browsers. Generally the webpage created for Firefox behaves pretty much the same in Chrome, but Internet Explorer has its own problems. Whether it be problem with <a href="http://viralpatel.net/blogs/2009/03/javascript-multiple-selection-listbox-problem-ms-internet-explorer.html">Multiple Selection in IE</a> or the <a href="http://viralpatel.net/blogs/2008/12/ajax-cache-problem-in-ie.html">AJAX Cache Problem</a>, Internet Explorer has always been a browser which needs special attention.</p><p>Thus, generally how we deal with IE is we create a separate stylesheet altogether and include it in the webpage whenever the client is using Internet Explorer.</p><h3>IE Only</h3><p>Here is the basic technique for an IE-Only stylesheet:</p><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie-only.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><h3>Non-IE Only</h3><p>The opposite technique, targeting only NON-IE browsers:</p><pre class="brush: xml; title: ; notranslate">
&lt;!--[if !IE]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;not-ie.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><p>If you need to get include stylesheet for specific versions of IE, here are a few examples.</p><h3>IE 7 ONLY</h3><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 7]&gt;
	&lt;link href=&quot;IE-7-SPECIFIC.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;&gt;
&lt;![endif]--&gt;
</pre><h3>IE 6 ONLY</h3><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 6]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;IE-6-SPECIFIC.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><h3>IE 5 ONLY</h3><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 5]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;IE-5-SPECIFIC.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><h3>IE 5.5 ONLY</h3><pre class="brush: xml; title: ; notranslate">
&lt;!--[if IE 5.5000]&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;IE-55-SPECIFIC.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><h3>VERSION OF IE VERSION 6 OR LOWER</h3><pre class="brush: xml; title: ; notranslate">
&lt;!--[if lt IE 7]&gt;
	&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;IE-6-OR-LOWER-SPECIFIC.css&quot; /&gt;
&lt;![endif]--&gt;
</pre><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/02/step-by-step-guide-to-crack-winrar.html" title="Step by step Guide to Crack WinRAR">Step by step Guide to Crack WinRAR</a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li><li><a href="http://viralpatel.net/blogs/2010/01/google-takes-china-stop-censoring.html" title="Google Takes on China; Will Stop Censoring Results">Google Takes on China; Will Stop Censoring Results</a></li><li><a href="http://viralpatel.net/blogs/2010/01/simplest-virus-fork-bomb.html" title="Simplest Virus – Fork Bomb">Simplest Virus – Fork Bomb</a></li><li><a href="http://viralpatel.net/blogs/2010/01/hacking-wifi-network-using-backtrack.html" title="Hacking Wifi Network Using BackTrack">Hacking Wifi Network Using BackTrack</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Rounded corner CSS without images</title><link>http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html</link> <comments>http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html#comments</comments> <pubDate>Thu, 06 Aug 2009 10:20:06 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[rounded corner]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1623</guid> <description><![CDATA[Lot of webdesigners uses rounded corner tables and divs to display information on the webpage. Not only it looks sleek but also eye appealing. The problem with coding such DIVs is that there is no standard way of rounding off the corners available in CSS (till now). Designers overcome this problem by using corner images [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/08/rounded-corner-css.png" alt="rounded-corner-css" title="rounded-corner-css" width="266" height="196" class="alignleft size-full wp-image-1626" />Lot of webdesigners uses rounded corner tables and divs to display information on the webpage. Not only it looks sleek but also eye appealing.</p><p>The problem with coding such DIVs is that there is no standard way of rounding off the corners available in CSS (till now). Designers overcome this problem by using corner images to display around a DIV to make it look rounded. But this approach is not always advisable as it makes the code tedious.</p><p>There are lot of code snippets around to create rounded corner DIVs using images. But here is a simple CSS technique of rounding off the corners of the DIV using some css attributes. This technique will work in Firefox, Safari, Chrome and any other CSS3-compatible browser. This technique will not work in Internet Explorer.</p><p>Add following CSS attributes to your element to make its corner round.</p><pre class="brush: css; title: ; notranslate">
selector {
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    border-radius: 10px;
    border: 1px solid;
}
</pre><p><img src="http://img.viralpatel.net/2009/08/all-corner-rounded-css.png" alt="all-corner-rounded-css" title="all-corner-rounded-css" width="413" height="37" border="0" /></p><p>To make only Top Left corner rounded, use following CSS.</p><pre class="brush: css; title: ; notranslate">
selector {
    -moz-border-radius-topleft: 10px;
    -webkit-border-top-left-radius: 10px;
    border: 1px solid;
}
</pre><p><img src="http://img.viralpatel.net/2009/08/top-left-corner-rounded-css.png" alt="top-left-corner-rounded-css" title="top-left-corner-rounded-css" width="413" height="37"  border="0" /></p><p>Similarly use topleft, top-left, bottom-right, bottomright etc for rounding off the corners of the DIV.</p><h3><a href="http://www.viralpatel.net/blogs/demo/css-rounded-corner-div-table/" target="_new">View Demo</a></h3><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li><li><a href="http://viralpatel.net/blogs/2009/11/20-very-useful-css-stylesheet-tips-tricks.html" title="20 Very Useful CSS Stylesheet Tips &#038; Tricks">20 Very Useful CSS Stylesheet Tips &#038; Tricks</a></li><li><a href="http://viralpatel.net/blogs/2009/09/change-form-input-textbox-style-focus-jquery.html" title="Changing Form Input (Textbox) Style on Focus using jQuery">Changing Form Input (Textbox) Style on Focus using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2009/02/compress-php-css-js-javascript-optimize-website-performance.html" title="Compress PHP, CSS, JavaScript(JS) &#038; Optimize website performance.">Compress PHP, CSS, JavaScript(JS) &#038; Optimize website performance.</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/08/rounded-corner-css-without-images.html/feed</wfw:commentRss> <slash:comments>28</slash:comments> </item> <item><title>HTML 5: The new HTML kid on the block!</title><link>http://viralpatel.net/blogs/2009/05/html-5-the-new-html-kid-on-the-block.html</link> <comments>http://viralpatel.net/blogs/2009/05/html-5-the-new-html-kid-on-the-block.html#comments</comments> <pubDate>Wed, 27 May 2009 07:51:03 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[General]]></category> <category><![CDATA[browsers]]></category> <category><![CDATA[html]]></category> <category><![CDATA[html5]]></category> <category><![CDATA[internet explorer]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=1328</guid> <description><![CDATA[Hope you all have heard that behind-the-scene progress of the new version of HTML, is cruising through. There are some good news for those preachers of web standards who give importance to the semantically correct web. With the the new version of HTML (HTML 5), still gazing towards the recommendation stage (the specification is not [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/2009/05/html5.png" alt="html5" title="html5" width="191" height="124" class="alignleft size-full wp-image-1330" />Hope you all have heard that behind-the-scene progress of the new version of HTML, is cruising through.<br /> There are some good news for those preachers of web standards who give importance to the semantically correct web.</p><p>With the the new version of HTML (HTML 5), still gazing towards the recommendation stage (the specification is not yet complete and it would take few more years), there are some wonderful elements/tags that are going to make HTML coding more sensible and structured business. These tags are specifically implemented for giving more semantically correct containers while coding HTML. Also there are many exciting features that comes with this new kid on the block, like more control over forms (web forms 2.0) and much more. These new additions are really gonna rock, and it really would be fun coding in the new version <img src='http://viralpatel.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><p>Let me list out some interesting tags of this new version, that some browsers already have started implementing support, but not in a complete manner.</p><h2>Interesting tags – HTML5</h2><h3>&lt;section&gt;</h3><p>A section is a thematic grouping of content, typically preceded by header, possibly with a footer after. sections can be nested inside of each other, if needed, and can hold any amount of typical markup.</p><h3>&lt;header&gt;</h3><p>The header of a section, typically a headline or grouping of headlines, but may also contain supplemental information about the section.</p><h3>&lt;footer&gt;</h3><p>A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.</p><h3>&lt;nav&gt;</h3><p>Defines the navigation area, typically a list of links. The nav should be a sibling of the main section, header, and footer.</p><h3>&lt;article&gt;</h3><p>An independent entry in a blog, magazine, compendium, and so on.</p><h3>&lt;aside&gt;</h3><p>An aside indicates content that is tangentially related to the content around it.</p><h3>&lt;audio&gt;</h3><p>Defines sound, like music or audio streams</p><h3>&lt;video&gt;</h3><p>Defines video, like video clip or streaming video</p><p>So a typical blog page would look like the following in HTML5</p><pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Standard Blog&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;header&gt;
      &lt;h1&gt;&lt;a href=&quot;#&quot;&gt;Standard Blog&lt;/a&gt;&lt;/h1&gt;
    &lt;/header&gt;
    &lt;nav&gt;
      &lt;ul&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Archives&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/nav&gt;
    &lt;section&gt;
      &lt;article&gt;
        &lt;header&gt;
          &lt;h1&gt;&lt;a href=&quot;#&quot;&gt;Title&lt;/a&gt;&lt;/h1&gt;
        &lt;/header&gt;
        &lt;section&gt;
          &lt;p&gt;Lorem ipsum...&lt;/p&gt;
        &lt;/section&gt;
      &lt;/article&gt;
      &lt;article&gt;
        &lt;header&gt;
          &lt;h1&gt;&lt;a href=&quot;#&quot;&gt;Title&lt;/a&gt;&lt;/h1&gt;
        &lt;/header&gt;
        &lt;section&gt;
          &lt;p&gt;Lorem ipsum...&lt;/p&gt;
        &lt;/section&gt;
      &lt;/article&gt;
      &lt;article&gt;
        &lt;header&gt;
          &lt;h1&gt;&lt;a href=&quot;#&quot;&gt;Title&lt;/a&gt;&lt;/h1&gt;
        &lt;/header&gt;
        &lt;section&gt;
          &lt;p&gt;Lorem ipsum...&lt;/p&gt;
        &lt;/section&gt;
      &lt;/article&gt;
    &lt;/section&gt;
    &lt;footer&gt;
      &lt;p&gt;Copyright © 2008 All Rights&lt;/p&gt;
    &lt;/footer&gt;
  &lt;/body&gt;
&lt;/html&gt;
</pre><h2>Can we use it right away?</h2><p>Actually, yes, with a few extra steps. And it will work in all modern browsers. It can even work in IE6. There are only a few little quirks we need to get past if we’re going to start using this today.</p><p>First, because most browsers don’t understand the new HTML5 doctype, they don’t know about these new tags in HTML5. Fortunately, due to the flexibility of browsers, they deal well with unknown tags. The only issue here is unknown tags have no default style, and are treated as inline tags. These new HTML5 tags are structural, and should obviously be block level elements. So, when we style them with CSS, we need to be sure to include display:block; in our attribute/value pairs.<br /> Include this simple extra piece of CSS, and these new tags are immediately usable. Starting today. And of course, once HTML5 is more widely supported, the display:block; can be removed, as it will be included in the browser default styles.</p><h2>Support in IE</h2><p>There is one more issue if you require IE support. Turns out that the IE rendering engine will work with the new tags, but will not recognize any CSS applied to them. Well, that’s no good. Fortunately, IE just needs a good swift kick with the help of a very simple bit of JavaScript. All we need to do to kick start IE is to create a DOM node with JavaScript for each of the new tags, and suddenly IE will apply styles to the new tags with no problem. The code will look something like this, and can be placed directly in the head of our document, or the contents of the script tag placed into an external file and included.</p><pre class="brush: jscript; title: ; notranslate">
&lt;script&gt;
  document.createElement('header');
  document.createElement('footer');
  document.createElement('section');
  document.createElement('aside');
  document.createElement('nav');
  document.createElement('article');
&lt;/script&gt;
</pre><p>So, lets try building a semantically correct web, with all these wonderful tags to our support …lets try out the new kid on the block <img src='http://viralpatel.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><em>This article was written by <a rel="nofollow" href="http://mysticpixels.wordpress.com/"><strong>MysticPixels</strong></a>, Author of Web 3.0, CSS and other articles. We welcomes your <a href="http://viralpatel.net/blogs/join-us">tips and guest articles</a>. You may want to login directly in this website using your Google/Yahoo/OpenID login and contribute.</p><p>If you liked this article, please submit it to your favorite social media sites.<br /> </em></p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2010/10/introduction-html5-domstorage-api-example.html" title="Introduction to HTML5 DOMStorage API with Example">Introduction to HTML5 DOMStorage API with Example</a></li><li><a href="http://viralpatel.net/blogs/2009/11/disable-back-button-browser-javascript.html" title="Disable Back Button in Browser using JavaScript">Disable Back Button in Browser using JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2009/09/setting-height-selectbox-combobox-ie.html" title="Setting Height of Selectbox (Combobox) in IE">Setting Height of Selectbox (Combobox) in IE</a></li><li><a href="http://viralpatel.net/blogs/2009/09/how-to-create-ie-specific-css-stylesheet.html" title="How To: Create an IE Specific Stylesheet">How To: Create an IE Specific Stylesheet</a></li><li><a href="http://viralpatel.net/blogs/2009/07/reducing-memory-usage-firefox-memory-hog.html" title="Reducing Memory usage in Firefox">Reducing Memory usage in Firefox</a></li><li><a href="http://viralpatel.net/blogs/2009/03/implement-simple-font-zoomer-in-javascript-html.html" title="Implement simple font zoomer in JavaScript &#038; HTML">Implement simple font zoomer in JavaScript &#038; HTML</a></li><li><a href="http://viralpatel.net/blogs/2009/03/javascript-multiple-selection-listbox-problem-ms-internet-explorer.html" title="Multiple Selection Listbox Javascript Problem in MS Internet Explorer">Multiple Selection Listbox Javascript Problem in MS Internet Explorer</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/05/html-5-the-new-html-kid-on-the-block.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Compress PHP, CSS, JavaScript(JS) &amp; Optimize website performance.</title><link>http://viralpatel.net/blogs/2009/02/compress-php-css-js-javascript-optimize-website-performance.html</link> <comments>http://viralpatel.net/blogs/2009/02/compress-php-css-js-javascript-optimize-website-performance.html#comments</comments> <pubDate>Wed, 04 Feb 2009 09:04:03 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Compression]]></category> <category><![CDATA[htaccess]]></category> <category><![CDATA[Javascript Compression]]></category> <category><![CDATA[Website optimization]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=771</guid> <description><![CDATA[Since few days we have been registering heavy traffic spikes on our website. This lead to performance issues. As this site is currently hosted on a shared hosting server, it is very difficult to optimize the performance of the site. We are using WordPress as CMS for this blog, hence we decided to install WP-Super [...]]]></description> <content:encoded><![CDATA[<p><img src="http://img.viralpatel.net/scrap-cars.jpg" alt="" title="scrap-cars" width="320" height="246" class="alignright size-full wp-image-772" /> Since few days we have been registering heavy traffic spikes on our website. This lead to performance issues. As this site is currently hosted on a shared hosting server, it is very difficult to optimize the performance of the site.</p><p>We are using <a rel="nofollow" href="http://www.wordpress.org"><strong>WordPress</strong></a> as CMS for this blog, hence we decided to install <strong>WP-Super cache plugin</strong> for WordPress to improve the performance. This plugin will create static HTML files from your blogs post and other pages and save them on web server. These HTMLs are served to client whenever consecutive requests are made. Hence this greatly improve the performance as it reduce PHP parsing and database connections.</p><p>Bandwidth control is an important task to be followed when your traffic is increasing. With limited monthly bandwidth hosting, your site may run out of bandwidth and thus result in increase in down time. Hence it is very much advisable to compress your websites response with GZip and then serve it to client. Compressing output can significantly improve your websites performance by reducing the size sometimes upto 80%!</p><p>So how can you enable GZip compression and compress your websites output? Well there are several ways to achieve this. I have listed out following very useful tricks to enable compression.</p><h2>GZip compression in Tomcat, JBoss server</h2><p>You can find a full post explaining this trick <a href="http://viralpatel.net/blogs/2008/11/enable-gzip-compression-in-tomcat.html"><strong>here</strong></a>.</p><h2>GZip using mod_gzip, mod_deflate and htaccess</h2><p>Apache server supports server level GZip compression with the help of module <strong>mod_gzip</strong> and <strong>mod_deflate</strong>. You can use this module and enable GZip compression for your website using htaccess file. First you have to check whether your hosting provider has enabled mod_gzip or mod_deflate module or not? To check this, you can use <strong>php_info()</strong> function of PHP which prints all the information about server and modules.</p><p>You can enable compression for text and html by adding following lines in your htaccess file.</p><pre class="brush: xml; title: ; notranslate">
# compress all text and html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

# Or, compress certain file types by extension:
&lt;Files *.html&gt;
SetOutputFilter DEFLATE
&lt;/Files&gt;
</pre><p>You can compress all type of content (image, css, js etc) using mod_deflate. Copy following code in htaccess to do this.</p><pre class="brush: xml; title: ; notranslate">
&lt;Location /&gt;
    SetOutputFilter DEFLATE
      SetEnvIfNoCase Request_URI  \
        \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI  \
        \.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary
&lt;/Location&gt;
</pre><p>Also, you can add following code in your htaccess file and enable compression using mod_gzip.</p><pre class="brush: xml; title: ; notranslate">
&lt;IfModule mod_gzip.c&gt;
    mod_gzip_on       Yes
    mod_gzip_dechunk  Yes
    mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler   ^cgi-script$
    mod_gzip_item_include mime      ^text/.*
    mod_gzip_item_include mime      ^application/x-javascript.*
    mod_gzip_item_exclude mime      ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
&lt;/IfModule&gt;
</pre><p>This technique only works if mod_gzip or mod_deflate modules are loaded in Apache. In our case, these modules were not there and our hosting provider refused to load it as we were using a shared hosting. So following can be another way of enabling compression.</p><h2>GZip using PHP ob_start() method</h2><p>If your hosting provider does not support mod_gzip module, ob_start() method can be used to  enable compression in PHP file. For this you need to copy following line in top of the PHP file. You may want to add this line in start of the header file that gets included in every php.</p><pre class="brush: php; title: ; notranslate">
&lt;?php
	if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
		ob_start(&quot;ob_gzhandler&quot;);
	else
		ob_start();
?&gt;
</pre><p>Above code will check whether your browser supports gzip, if yes, then it send ob_gzhandler method as handle to ob_start method which buffers the output. Thus output is compressed using <strong>ob_gzhandler</strong>. Only problem with this method is that you have to manually edit all PHP files or should have a header.php file that gets included in all files. There are still ways to achieve this without touching your PHP files. Read following trick.</p><h2>GZip using php_value directive in htaccess</h2><p>php_value directive can be used to append/prepend any PHP files in the request of change the output handler. First we will see how we can prepend a PHP file and achieve this. Copy the PHP code that we saw in above example in a file called <em>gzip-enable.php</em>. Now copy following lines in your htaccess file. Thus you need not to modify any of your PHP files can can prepend a PHP file with ob_start() method to all the files.</p><pre class="brush: xml; title: ; notranslate">
&lt;FilesMatch &quot;\.(txt|html|htm|php)&quot;&gt;
    ForceType application/x-httpd-php

	php_value auto_prepend_file /the/full/path/gzip-enable.php

&lt;/FilesMatch&gt;
</pre><p>But what if you don&#8217;t want to prepend a PHP file? Still there is a way to specify default output handler using htaccess. Use following line in your htaccess file to tell your apache to register ob_gzhandler handler function as output handler.</p><pre class="brush: xml; title: ; notranslate">

    php_value output_handler ob_gzhandler
</pre><h2>Compress CSS using htaccess and php_value</h2><p>CSS Stylesheet files occupy significant size in overall webpage size. It is hence advisable to compress these files before sending them to client. This significantly improve the performance of a webpage. For compressing CSS files, we will first create a PHP file <em>gzip-css.php</em> with following code.</p><pre class="brush: php; title: ; notranslate">
&lt;?php

   // initialize ob_gzhandler function to send and compress data
   ob_start (&quot;ob_gzhandler&quot;);

   // send the requisite header information and character set
   header (&quot;content-type: text/css; charset: UTF-8&quot;);

   // check cached credentials and reprocess accordingly
   header (&quot;cache-control: must-revalidate&quot;);

   // set variable for duration of cached content
   $offset = 60 * 60;

   // set variable specifying format of expiration header
   $expire = &quot;expires: &quot; . gmdate (&quot;D, d M Y H:i:s&quot;, time() + $offset) . &quot; GMT&quot;;

   // send cache expiration header to the client broswer
   header ($expire);
?&gt;
</pre><p>Now add following lines in your htaccess file to enable compression for CSS files.</p><pre class="brush: xml; title: ; notranslate">
&lt;FilesMatch &quot;\.(css)&quot;&gt;
    ForceType application/x-httpd-php

	php_value auto_prepend_file &quot;/the/full/path/of/this/file/gzip-css.php&quot;

&lt;/FilesMatch&gt;
</pre><p>Whenever a http request for .css will come to a server, the type of css will get converted to application/x-httpd-php, thus making them parsed using PHP. Then a file gzip-css.php will be prepend to this request which in turns compress the output using <em>ob_start (&#8220;ob_gzhandler&#8221;)</em> method.</p><h2>Compress JavaScript (JS) using htaccess and php_value</h2><p>Similar to above example for CSS, JavaScript files can also be compressed and sent to client. For this create a PHP file gzip-js.php and copy following code in it.</p><pre class="brush: php; title: ; notranslate">
&lt;?php

   // initialize ob_gzhandler function to send and compress data
   ob_start (&quot;ob_gzhandler&quot;);

   // send the requisite header information and character set
   header (&quot;content-type: text/javascript; charset: UTF-8&quot;);

   // check cached credentials and reprocess accordingly
   header (&quot;cache-control: must-revalidate&quot;);

   // set variable for duration of cached content
   $offset = 60 * 60;

   // set variable specifying format of expiration header
   $expire = &quot;expires: &quot; . gmdate (&quot;D, d M Y H:i:s&quot;, time() + $offset) . &quot; GMT&quot;;

   // send cache expiration header to the client broswer
   header ($expire);
?&gt;
</pre><p>Also add following lines in your htaccess file.</p><pre class="brush: xml; title: ; notranslate">
&lt;FilesMatch &quot;\.(js)&quot;&gt;
    ForceType application/x-httpd-php

	php_value auto_prepend_file &quot;/the/full/path/of/this/file/gzip-js.php&quot;

&lt;/FilesMatch&gt;
</pre><p>Do you know other methods of compressing the output of PHP/JS/CSS files? Let me know, I will try to add them in this tutorial.</p><p>Happy Compressing <img src='http://viralpatel.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2008/12/increase-performance-of-website-by-compressing-javascript.html" title="Increase performance of website by compressing JavaScript.">Increase performance of website by compressing JavaScript.</a></li><li><a href="http://viralpatel.net/blogs/2012/01/create-zip-file-javascript.html" title="Create ZIP Files in JavaScript">Create ZIP Files in JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2010/12/password-protect-your-webpages-using-htaccess.html" title="Password Protect your webpages using htaccess">Password Protect your webpages using htaccess</a></li><li><a href="http://viralpatel.net/blogs/2009/11/php-fatal-error-time-htaccess.html" title="PHP Fatal Error Maximum Execution Time Issue &#038; htaccess">PHP Fatal Error Maximum Execution Time Issue &#038; htaccess</a></li><li><a href="http://viralpatel.net/blogs/2009/11/avoid-image-hotlinking-bandwidth-theft-website.html" title="How To Avoid Image Hotlinking &#038; Bandwidth Theft In Your Website">How To Avoid Image Hotlinking &#038; Bandwidth Theft In Your Website</a></li><li><a href="http://viralpatel.net/blogs/2009/06/21-very-useful-htaccess-tips-tricks.html" title="21 very useful htaccess tips &#038; tricks">21 very useful htaccess tips &#038; tricks</a></li><li><a href="http://viralpatel.net/blogs/2009/04/analyze-website-using-online-website-analyzer-tools.html" title="Analyze website using online Website Analyzer Tools">Analyze website using online Website Analyzer Tools</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2009/02/compress-php-css-js-javascript-optimize-website-performance.html/feed</wfw:commentRss> <slash:comments>60</slash:comments> </item> <item><title>Setting opacity of html element using Javascript</title><link>http://viralpatel.net/blogs/2008/11/setting-opacity-of-html-element-using-javascript.html</link> <comments>http://viralpatel.net/blogs/2008/11/setting-opacity-of-html-element-using-javascript.html#comments</comments> <pubDate>Fri, 28 Nov 2008 10:17:58 +0000</pubDate> <dc:creator>Viral Patel</dc:creator> <category><![CDATA[CSS]]></category> <category><![CDATA[JavaScript]]></category><guid isPermaLink="false">http://viralpatel.net/blogs/?p=223</guid> <description><![CDATA[You must have seen the blur effect of html elements like table, div where the opacity of these elements are slowly made to transparent or opaque. This can be acheived through javascript. Internet Exlporer supports a CSS attribute called filter, wherein you can apply lot of different filter options available in browser. There are currently [...]]]></description> <content:encoded><![CDATA[<p>You must have seen the blur effect of html elements like table, div where the opacity of these elements are slowly made to transparent or opaque. This can be acheived through javascript.</p><p>Internet Exlporer supports a CSS attribute called <code>filter</code>, wherein you can apply lot of different filter options available in browser. There are currently three categories of filters &#8211; Visual filters and Reveal/Blend Transition filters. Multiple filters can be applied to a selector to produce interesting results, with the order of application often playing an important role in the final visual result. Current filters only apply in a visual context, but the extensibility of the property could allow for other capabilities.</p><p>Hence following code can be used to set opacity of an html element in IE.</p><pre class="brush: jscript; title: ; notranslate">
var opacityValue = 0.5; //make it 50% opaque
myElement.style.filter = &quot;alpha(opacity=&quot; + opacityValue*100 + &quot;)&quot;; // IE
</pre><p>But the above code will not work with other browsers like Firefox, Opera etc. Firefox supports another CSS property called <code>opacity</code> which controls the opacity of an element.<br /> Following javascript function will set the opacity of any html element irrespective of the browser.</p><pre class="brush: jscript; title: ; notranslate">
function setOpacity (myElement, opacityValue) {
	if (window.ActiveXObject) {
		myElement.style.filter = &quot;alpha(opacity=&quot;
			 + opacityValue*100 + &quot;)&quot;; // IE
	} else {
		myElement.style.opacity = opacityValue; // Gecko/Opera
	}
}
</pre><div id="relatedpost"><h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://viralpatel.net/blogs/2009/02/compress-php-css-js-javascript-optimize-website-performance.html" title="Compress PHP, CSS, JavaScript(JS) &#038; Optimize website performance.">Compress PHP, CSS, JavaScript(JS) &#038; Optimize website performance.</a></li><li><a href="http://viralpatel.net/blogs/2012/01/stopsopa-jquery-plugin.html" title="STOP SOPA JQuery Plugin">STOP SOPA JQuery Plugin</a></li><li><a href="http://viralpatel.net/blogs/2012/01/create-zip-file-javascript.html" title="Create ZIP Files in JavaScript">Create ZIP Files in JavaScript</a></li><li><a href="http://viralpatel.net/blogs/2010/12/dynamically-shortened-text-show-more-link-jquery.html" title="Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery">Dynamically shortened Text with &#8220;Show More&#8221; link using jQuery</a></li><li><a href="http://viralpatel.net/blogs/2010/11/multiple-checkbox-select-deselect-jquery-tutorial-example.html" title="Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example">Multiple Checkbox Select/Deselect using jQuery &#8211; Tutorial with Example</a></li><li><a href="http://viralpatel.net/blogs/2010/01/javascript-array-remove-element-js-array-delete-element.html" title="JavaScript Array Remove an Element ">JavaScript Array Remove an Element </a></li><li><a href="http://viralpatel.net/blogs/2010/01/firefox-3-6-released-css-gradient-feature.html" title="Firefox 3.6 Released: With New CSS Gradient Feature">Firefox 3.6 Released: With New CSS Gradient Feature</a></li></ul></div>]]></content:encoded> <wfw:commentRss>http://viralpatel.net/blogs/2008/11/setting-opacity-of-html-element-using-javascript.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: viralpatel.net @ 2012-02-08 21:14:23 -->
