CSS Hack: Getting Safari to behave



Author: Dustin Brewer

Safari is one of those tricky browsers that aren't the most cooperative but there aren't many hacks for it that will work. Unlike IE that allows you to target the browser directly easily, Safari doesn't offer that solution within XHTML. I could only come up with 2 ways to use CSS hacks or tricks for Safari specifically.

The best step towards making sure all browsers work the same for your site is to use valid XHTML Strict code, this helps most of the time. But, sometimes you do have to venture away from that ideal.

It is my goal to not have to make a site non-standards compliant and I will typically test many different ways of doing things on a site if it isn't working for Safari, IE6 or IE7. I typically will write my code for Firefox so I don't run into many issues with it not working properly. Opera doesn't usually need any CSS hacks because it is the most standards compliant browser. It is the only browser that passes the ACID2 test, a standards compliance browser test.

Target Safari with CSS hacks

Anyway, on to the actually Safari hacks... assuming that you haven't tried my method of doing whatever is broken in a different way until you can get the same results on your browsers.

The first one is the one I hate to use but I will throw it out there first. Basically anytime you add an extra # sign Safari is the only browser that will read any of the CSS after that point. Unfortunately that will cause your CSS to not validate. So you typically don't want to use this method unless you are in a pinch.

There is one other way to target Safari, it is by using the min-device-pixel-ratio class from CSS3 that is currently only supported by Safari 3.0 and Opera 8 & 9. This is a difficult way to remember to target Safari but it does work. Below is an example of how to use it to target Safari specifically using Safari's webkit as a precursor.

@media screen and (-webkit-min-device-pixel-ratio:0){
#div {margin-left: 10px;}
}

However, just like a good portion of the true CSS hacks they will not only target that browser forever. So you want to be sure to keep a list or at least check back on websites that you know you have used hacks on

Target Safari with javascript

The other way, and more more usable way is to use javascript to target a browser. This is probably another one of the best ways to target any browser specifically the only downfall is they have to have javascript enabled. Typically though most people that would even dream of having javascript disabled are web developers like us testing things. Usually when we accidentally leave it off though, we notice pretty quickly that we left it off.

Below is how you would target Safari with javascript:

<script type="javascript"> isSafari3 = false; if(window.devicePixelRatio) isSafari3 = true; </script>

That should be all you need to get Safari all fixed up for whatever web project you are working on. I will be posting an article soon about how to use javascript to target just about every browser that is targetable. This will help a lot with trying to get your websites to work the way they should for all browsers.

About the Author:
Dustin Brewer is a web designer located in Oklahoma City, OK specializing in aesthetics in design, web standards, accessibility and usability. He also enjoys helping others to discover CSS and web design best practices through his web site, dustin brewer, a web design news site. "


Total Word Count: 640
Click here to View more Articles at: Invision-Graphics
Invision-Graphics Article Source:

Approved on Wednesday, September 12 @ 16:29:10 EDT by Shawn DesRochers
 
Options
 Return to the main page Return Home

 Print Page Print Version

 Send to a Friend Send To A Friend

 Discuss Article Discuss Article

 Related Articles Related Articles

 Search Articles Search Articles

 Stories Archive Stories Archive

 Subscribe Newsletter Subscribe Newsletter

 Syndicate Article Topic: CSS XML News Feed

 Contact US Contact US
Article Rating
Average Score:
Votes: 0

Rate this article:
CSS Hack: Getting Safari to behave

CSS Hack: Getting Safari to behave – Aticle Rating 5 Stars
CSS Hack: Getting Safari to behave – Aticle Rating 4 Stars
CSS Hack: Getting Safari to behave – Aticle Rating 3 Stars
CSS Hack: Getting Safari to behave – Aticle Rating 2 Stars
CSS Hack: Getting Safari to behave – Aticle Rating 1 Star


Syndicate Article
 My Yahoo!
 Google
 NewsGator
 Stumbleupon
 PluckIT
 Rojo
 Bloglines
 My AOL
 Blogrolling
 ENewsblog
 NewsIsFree
 NetVibes
 del.icio.us
 Technorati
 Digg This
 FeedBurner
 FeedMailer
Sponsor Advertising
Blogging Fusion Blog Directory
Submit your blog to Blogging Fusion Blog Directory for FREE. Start increasing your backlinks and traffic today!

Text Advertising Info Text Advertising Info
Support US

Make a donation!
If you enjoy our services, make a donation today!

Google Support Ads
Related Links
W3C CSS
More about CSS
News by Admin


Advertise Here

Most read story about CSS:
CSS Hack: Getting Safari to behave

Book Advertising
Get this Book Now
Buy this Book Now!
Click Here
Comment on Article:"CSS Hack: Getting Safari to behave" Login | Create an Account | 0 comments
The following comments are owned by the individual who posted them. Invision-Graphics is not responsible for the content or the accuracy of the following statements.
No Comments Allowed for Anonymous, please Register
Related Categories
Technorati TagsTechnorati Tags


Click Here to Advertise
Affordable Hosting! http://www.invision-graphics.com/images/banners/468X60_VISIONHOSTING.gif
 Today: 8,249  Yesterday: 39,154  Total Hits: 41,511,777
Page Rendered in: 0.09s - Total Queries: 38 - MySQL DB: 18.8 mb's - Pages served in past 5 minutes: 161