Target IE6 and IE7 Browsers without Conditional Comments

Need to target IE browsers? Here is a quick hack that doesn’t require conditional comments (note that your CSS will therefore not pass auto-validation, which is fine if you are aware of why it doesn’t).

The code below will change the background-color of divs depending on what browser the user is viewing the web page under. Since * cascades down to IE7 and below, we use _ after that declaration so that IE6 (and below) has a different background colour from IE7.

div {
    background-color: #999; /* all browsers */
    *background-color: #ccc; /* add a * before the property - IE7 and below */
    _background-color: #000; /* add a _ before the property - IE6 and below */
}
Advertisements

Easy Web Fonts with Google Font API

Web fonts allow you to step outside of the normal web-safe fonts by taking advantage of CSS’s @font-face rule. However, right now, browsers aren’t uniform in its implementation of @font-face. More specifically, web browsers differ in the types of font files they support (hopefully this will change with the WOFF standards). Additionally, you must be careful with the fonts you use since some of them might not be licensed for web use.

To sidestep the issues with @font-face, the Google Font API is here to the rescue. Here is an example of using the Cantarell font on elements that takes advantage of Google Fonts API. If you want to use the Cantarell font from Google Font API, first reference the remote stylesheet inside your tags:

href="http://fonts.googleapis.com/css?family=Cantarell"

To use the font in h1 elements, simply use the font-family CSS property.

h1 {
    font-family: 'Cantarell', Arial, serif; /*Use a font stack, just in case.*/
}

 

Google Doctype

Google Doctype is an open encyclopedia and reference library. Written by web developers, for web developers. It includes articles on web security, JavaScript DOM manipulation, CSS tips and tricks, and more. The reference section includes a growing library of test cases for checking cross-browser and cross-platform compatibility.