Style Sheets
  Home arrow Style Sheets arrow Page 5 - Cross Browser Issues: CSS Hacks, Understan...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Cross Browser Issues: CSS Hacks, Understanding Compatibility
By: Jennifer Sullivan Cassidy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 21
    2006-01-03

    Table of Contents:
  • Cross Browser Issues: CSS Hacks, Understanding Compatibility
  • Know the Browsers
  • Know More Browsers, and Differences
  • How to Handle Differences
  • Another CSS Solution

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Another solution to issues of cross-browser compatibility would be to create multiple style sheets for multiple browsers, then using a JavaScript code to return the version and type of browser the web visitor is using.  I’ll talk more about this in the next article.  Still, even with the support of both strict mode and quirks mode in these browsers, there are going to be design issues.  Let’s look at a few workarounds and why they work the way they do, but we’ll really delve more into the hacks in the next article.

    The first one I want to look at is the “html>body” selector.  This selects any body element that is a child of an HTML element.  The problem though is the child selector will be interpreted correctly in compliant browsers only if there is white space on either side of it (html > body or html> body or html >body), except in IE.

    html>body { overflow: visible; } /* show to IE */
    body { overflow: auto; } /* show to everyone else */

    This is a manifestation of the underscore hack, which allows you to show CSS only to IE and exclude all other browsers.  This comes in very handy when you are needing to give IE a set of separate instructions because something won’t appear correctly if you don’t.

    The underscore hack looks like this:
    body {
        background: blue; /* show to Mozilla/Safari/Opera */
        _background: red; /* show to IE */
    }

    Two things I will point out about this workaround:  one, your CSS won’t validate; and two, it doesn’t work in IE 5 for Mac.  For this case, we have to add another hack, called the Mac Backslash Hack (try saying it three times really fast).  The normal function of this hack is to get IE5/Mac to ignore any CSS rules contained within the hack’s boundaries. This hack works by escaping an end-comment marker using a backslash before the asterisk: \*/.  This hides the end-comment marker for IE5/Mac, and tricks IE5/Mac into thinking anything which follows is still part of the comment. Once another unescaped end-comment marker appears, IE5/Mac resumes application of the remaining CSS rules. All other browsers understand the escaped end-comment as the actual end of the comment, and apply the following rules as if nothing ever stopped them from doing so.

    body {
        background: blue; /* show to Mozilla/Safari/Opera */
        _background: red; /* show to IE */
        /* commented backslash hack for IE5-Mac \*/
        background: green;
        /* end hack */
    }

    Hacks, as you can see from the example above, can get pretty complicated if you don’t understand the bugs that the browsers have to begin with.  You can find pretty good list of reported CSS bugs for particular browsers either on the browser’s own site or elsewhere on the Internet.  The next article will have many more hacks and workarounds, and hopefully this overview of why CSS sometimes really does behave oddly in certain browsers was helpful to you. 


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for the heads up! Even though I have been developing for a while, for some...
       · This article has several major flaws. #1 - The claim that special care should...
       · The easiest way to handle CSS bugs in IE is with separate stylesheet.
       · I might point out that what it says is that it is something you could do. Honestly,...
       · Oh, and by the way: the link you posted says that their information is outdated...
     

    STYLE SHEETS ARTICLES

    - Image Replacement CSS Techniques
    - Using BlueTrip`s Success, Notice and Error C...
    - More Uses for the Thin and Caps CSS Classes ...
    - Styling Definition Lists with the BlueTrip C...
    - Styling Unordered and Ordered HTML Lists wit...
    - Using the BlueTrip CSS Framework`s Thin and ...
    - Adding Borders to Web Page Columns with Blue...
    - Introducing the BlueTrip CSS Framework
    - Using a Background Grid to Assist Web Page L...
    - Extending the Rule Of Thirds for Web Page La...
    - A Two-Column Web Page Layout Based on the Ru...
    - Using the Rule Of Thirds for Web Page Layout
    - Swapping Columns Using the Divine Ratio for ...
    - Using the Golden Ratio in Liquid Web Page De...
    - Fundamental Design Principles for Web Page L...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek