Conditional CSS Comments

Home » Blog » Conditional CSS Comments

conditional CSS comments allow you to use different stylesheets to different browser. So you can assign different styles for different browsers.

Importance of Using Conditional CSS

  • Target CSS to any web-browser.
  • Optimise your CSS.
  • You can separate CSS for different browsers.
/*CSS FOR ONLY IE*/
<!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->

/*CSS FOR ONLY IE 5*/
<!–-[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]–->

/*CSS FOR ONLY IE 5.0*/
<!-–[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]–->

/*CSS FOR ONLY IE 5.5*/
<!–-[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]–->

/*CSS FOR ONLY IE 6*/
<!-–[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]–->

/*CSS FOR ONLY IE 7*/
<!–-[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]–->

/*CSS FOR Greater than IE 5*/
<!–-[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]–->
/*CSS FOR Less than IE 6*/
<!–-[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]–->

/*CSS FOR Less than equal to IE 5.5*/
<!–-[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]–->
/*CSS FOR Greater than IE 6*/
<!–-[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]–->

If you want to use Different Styles for different browsers in your CSS files or within the style tag

For IE6

*html .your_class
	{
	/* Your Style*/
	}
/* FOR ID*/

*html #your_ID
	{
	/* Your Style*/
	}
For IE7

*+html .yourclass
{
	/* Your Style*/
}
/* FOR ID*/
*+html #your_ID
{
	/* Your Style*/
}
For Google Chrome, opera, safari

body:nth-of-type(1) .your_class
{
/* Your Style*/
}
/*For ID*/

body:nth-of-type(1) #your_ID
{
/* Your Style*/
}

9 Comments on "Conditional CSS Comments"

  1. hneulovfmgt says:

    Excellent Article. It will solve problems for browser compatibility.

    Reply →
  2. hnulovfmgt says:

    Nice Article. Yes browser compatibility will be solved using this methods

    Reply →
  3. vyugvoflet says:

    Excellent site with good stuff.

    Reply →
  4. Sunil Chavan says:

    Really HelpFull!!!!!!!

    Reply →
  5. Phil says:

    hi – thanks for the post. quick question – is there any to target OS as opposed to browser? for example, using a particular css file for Mac but not Windows? thanks!

    Reply →
  6. JiGuang says:

    Brilliant article!

    Reply →

Trackbacks for this post

  1. Steps to Write Better Css | SNilesh.com

Got something to say? Go for it!

How to remove the http://t.co/XhUQ8T6p link from Login / Register Page: On self hosted wordpress blogs wordpress ... http://t.co/LWDOuEfq - 1 week ago