My Leading Project LOTO

Undoutable trust

Powered by Blogger.

Saturday, November 14, 2015

Filled Under:

css hacks

Share

 

CSS Hacks

 If you actively maintain a site (because it's your personal blog, for instance) CSS hacks are less dangerous. When browser compatibility patterns shift you can easily update the offending CSS.

There are an incredible number of CSS hacks available that are said to make sure that certain styles are or aren't parsed by certain browsers. In general I strongly feel you shouldn't use them.

The safe list

Below I started a list of safe hacks, that is, a list of hacks that are extremely unlikely to misfire in the future.
  1. The @import hack against Netscape 4. This browser is extremely dead by now.
    Any style sheet you import is not parsed by Netscape 4. Hence you should move all declarations that don't work in Netscape 4 to this style sheet.
     
    @import('notForNetscape4.css');
     
    Netscape 4 will not read the CSS in the notForNetscape4.css file.
  2. The commented backslash hack (original) against Explorer 5 Mac. This browser, too, is dead.
    The commented backslash hack works as follows:
    selector {
     property: value for Explorer 5 Mac
    }
    
    /*
     First comment. Explorer 5 Mac
     misses the end-of-comment
     because of the backslash
    \*/
    
    selector {
     property: value for all other browsers
    }
    
    /*
     Second comment. Explorer 5 Mac
     sees the end of this
     comment as the end of
     the previous one
    */
      
  3. Conditional comment ,aimed at Explorer Windows only.
That's it. I don't use any more hacks. In general I advise you to do the same.

Conditional comments

Conditional comments only work in IE, and are thus excellently suited to give special instructions meant only for IE. They are supported from IE 5 up until IE9 (inclusive).
Older IE versions frequently need some extra CSS in order to show your pages right. Conditional comments are the best way to add this CSS, since the system is explicitly designed for this use case.
If you need special styles for IE10 or up you’ll have to find another method, since conditional comments were disabled in IE10. However, these versions are much less buggy than the earlier ones.

0 comments:

Post a Comment