- Tutorials / HTML & CSS
- Tuesday, 12th Apr, 2011
Home » Tutorials » HTML & CSS » CSS Conditional Comment
Today, we are going to talk about CSS conditional comment for various browser. Have you guys read the post entitled ‘CSS3: Media Queries For Multiple Devices’ that posted in past few months ago ? If you haven’t, you can go and give the previous post a read.
Ok, so what is CSS conditional comment? Actually, CSS conditional comment was developed out of the desire to overcome CSS rendering bugs in a wide range of web browsers, ensuring as many visitors as possible see your website’s design correctly. Initially, this method was found in Internet Explorer allowing web designer / developer to overcome layout rendering problem, and now it was extended to include other browsers such as Gecko-based browsers and Webkit-based browsers.
The format of writing a CSS conditional statement is quite easy, you can use either way as stated below:
[if browser-name {CSS code here} ]
[if browser-name version {CSS code here} ]
[if conditional-operator browser-name version {CSS code here} ]
Is easy right? Let’s move on!
Now, we know the format of writing a conditional statement, the next thing we need to do is find out the name for each browser, so that we can cater the specific style sheet for specific device. Following is the full list of the browser’s name for the desktop and mobile devices:
For example, we just only want certain CSS code being display in Windows Mobile Phone, so we can write our conditional statement in this way:
<!--[if IEMobile]>
.myClassName {
color: red;
}
<![endif]-->
Simple right? Try it now!
Are you enjoying this article? Share it to your friends! and join onlyWebPro Facebook Like page to get more latest updates! onlyWebPro Facebook Like Page
CSS3: Spinner Animation
Introduction To Device Orientation With HTML5
HTML5 Canvas For Absolute Beginners – Part 4