blogging@Zed-Axis
CSS Hacks Using Browser Specific Selectors
Posted on:  Sep 30, 2008

Earlier, the main problem with the CSS has been lack of browser support. CSS Browser Selector gives us the ability to write specific CSS code for each operating system and each browser. To send different CSS rules to IE, we can use the child selector command, which IE can’t recognize.

The child selector command involves two elements, one of which is the child of the other. So, html>body refers to the child, body, contained within the parent, html. Browser detection using CSS hacks works by sending one CSS rule to the browser you're trying to trick, and then send a second CSS rule to the other browsers, overriding this first command.

 If you have two CSS rules with identical selectors then the second CSS rule will always take precedence. Here is the list of some useful browser specific selectors when we need to change a style in one browser but not the others.

 IE 6 and below

* html {}

 IE 7 and below

*:first-child+html {}

* html {}

 IE 7 only

*:first-child+html {}

IE 7 and modern browsers

only html>body {}

Modern browsers

only (not IE 7) html>/**/body {}

Opera versions 9 and below

html:first-child {}

Safari

html[xmlns*=""] body:last-child {}

 Place the code in front of the style to use these selectors. For example:

#content-box { width: 300px; height: 150px;

}

* html #content-box {

width: 350px;

} /* overrides the above style and changes the width to 350px in IE 6 and below */

   AddThis Feed Button
Reader's Comments
Neo
 Aug 17, 2009 at 13:26 PM
Well I write different css codes for different browsers...Though it consumes a lot of time I find it hack free Thanks
Post your comment
(*) marked fields are mandatory
Name:*  
Email Address:*
Website/Blog URL:
Comments:*

 
Security Code:*
 
 
Note: Comment Moderation has been enabled. Kindly bear with us till the blog administrator approves them to be published.
Follow us on Facebook Follow us on TwitterRSS Feed LinkedIn
 Recent Posts
How well are you Managing Your Inventory?
Saving Cost on After-Sales Service - An Indirect Profit Stream
Importance of Service Management Software in Consumer Durable Industry
How Important is the After Sales Process in consumer durable industry?
Happy Holi
 Tags
 Subscribe
AddThis Feed Button
Zed-Axis BlogSubscribe to Zed-Axis Newsletter
 Categories
 Take our opinion Poll
 Media Updates
 News
 Press Releases
 Zed-Axis@Twitter
 Archives
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009