Style Sheets
  Home arrow Style Sheets arrow Page 2 - Cross Browser Issues: CSS Hacks Explained,...
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 
Sun Developer Network 
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 Explained, Tips, Tricks and Fixes
By: Jennifer Sullivan Cassidy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 17
    2006-01-25

    Table of Contents:
  • Cross Browser Issues: CSS Hacks Explained, Tips, Tricks and Fixes
  • The Use of JavaScript and CSS
  • Hiding CSS from Buggy Browsers
  • Workarounds for Internet Explorer
  • More Workarounds for Internet Explorer

  • 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


    Cross Browser Issues: CSS Hacks Explained, Tips, Tricks and Fixes - The Use of JavaScript and CSS


    (Page 2 of 5 )

    There have been some coders that have found a way to incorporate JavaScript into CSS in order to avoid using hacks for browser compatibility.  While this may sound great, there are still several browsers that don’t support JavaScript in the CSS files, like Firefox, Opera, and Netscape.  Fortunately, most of those browsers don’t need to support the JavaScript in the CSS, since the modern versions of them handle CSS rather well.  It’s usually IE you have to worry about, but you are still going to run into a problem for those who disable JavaScript in their browsers.

    Still, the following example demonstrates the use of JavaScript in an external style sheet:

    document.tags.H1.color = "blue"
    document.tags.H1.fontSize = "20pt";

    document.tags.H2.textAlign = "left";

    This method isn’t new, however. It is really a JavaScript Style Sheet, or JSSS, which was actually submitted to the W3C in 1996 by Netscape as a method of offering an alternative to CSS, which at that time wasn’t widely accepted.   It has severe limitations as far as positioning, but other features like dynamic calculations and conditional processing could be pretty powerful.  JSSS is no longer supported in Netscape 6 and higher.  JSSS style sheets may also seem less friendly than CSS style sheets to users without programming backgrounds.

    Multiple Style Sheets for Multiple Browsers

    While it may be your choice to only offer a single style sheet for all browsers, you may decide you wish to serve a separate style sheet for each type of browser, especially due to the vast differences in the way browsers support CSS.  In this case, you’ll need a way to detect the visitor’s browser type and version, and then show the correct style sheet based on the results.

    A simple JavaScript script can detect a browser type and version, and then choose the style sheet that was written for that browser:

    <script language="JavaScript"><!--

    version=parseInt(navigator.appVersion); 

    if (navigator.appVersion.indexOf('5.')>-1){

    version=5

    }; 

    if (navigator.appVersion.indexOf('6.')>-1){

    version=6

    };

    if (navigator.appVersion.indexOf('7.')>-1){

    version=7

    };

    browser='OTHER';

    if (navigator.appName=='Netscape'){

    browser='NS'+version;

    }

    if (navigator.appName=='Microsoft Internet Explorer'){

    browser='MSIE'+version;

    }

    if (navigator.appVersion.indexOf('MSIE 4')>0) {

    browser='MSIE4';

    }

    if(browser == 'NS5'){

    browser='NS6'

    };

    //Internet Explorer

    if (browser=='MSIE4') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/msie4.css">');

    }

    if (browser=='MSIE5') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/msie5.css">');

    }

    if (browser=='MSIE6') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/msie6.css">');

    }

    //Netscape

    if (browser=='NS4') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/nn4.css">');

    }

    if (browser=='NS6') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/nn6.css">');

    }

    if (browser=='NS7') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/nn7.css">');

    }

    //everyone else

    if (browser=='OTHER') {

    document.write('<link rel="stylesheet" type="text/css" href="/css/other.css">');

    }

    // --></script>

    Obviously, you will have to create a separate style sheet for each browser in your script.

    More Style Sheets Articles
    More By Jennifer Sullivan Cassidy


     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT