Journal

Thoughts, ruminations, observations, and inspiration from theMechanism.

Safari CSS hack

March 28, 2007 | Posted by Jeffrey Barke | 11 comments

Please note that this hack does not work in Safari 3. The updated hack is here.

While I’m not a fan of CSS hacks in general, there comes a time when nothing else will solve the problem. This was the situation this morning—the site looked perfect in every browser except Safari (due to a background repeat bug), and I needed a quick way to apply CSS rules to Safari alone. Here’s the hack:

Place the pound sign ( # ) after a semi-colon ( ; ), all styles within those brackets and the remainder of the stylesheet will be ignored in Safari.

Example: The following code will make any <p> assigned the callout class red with normal font-weight in Safari, but black and bold in the rest of the browsers.
p.callout { color:#FF0000; font-weight:normal; }
p.callout { color:#000000; font-weight:bold;# }

[demo]

Tested on Mac OS X version 10.4.9 with Safari version 2.0.4 (419.3) and Mozilla Firefox version 2.0.0.3. Tested on Windows XP SP 2 with Mozilla Firefox version 2.0.0.3, Opera 9.10, and Microsoft Internet Explorer 6 and 7. Hack from bballcity

Spread the Love

del.icio.us:Safari CSS hack digg:Safari CSS hack spurl:Safari CSS hack wists:Safari CSS hack simpy:Safari CSS hack newsvine:Safari CSS hack blinklist:Safari CSS hack furl:Safari CSS hack reddit:Safari CSS hack blogmarks:Safari CSS hack Y!:Safari CSS hack smarking:Safari CSS hack magnolia:Safari CSS hack segnalo:Safari CSS hack

11 Comments So Far

  • Thanks to Jonathan Badeen at badeen.com for pointing out the pesky error at one our sites: Esopus Meadows Lighthouse. Now that we’ve learned that even the mighty Apple mocks the web designer, we have a new “naughty” check mark next to the Safari Browser in our “list of evil.”

    Great job sussing that one, Jeffrey!

  • Yeah I see to use this one quite often when the design has kind of a complicated background, safari usually throws it 1px to the left, while IE throws it off 1px to the right =\

    and the design requires pixel “perfectedness”

  • Great code but same code Can we repeat in the same page by different class?

    p.callout { color:#FF0000; font-weight:normal; }
    p.callout { color:#000000; font-weight:bold;# }

    p.call { color:#000000; font-weight:normal; }
    p.call { color:#FF0000; font-weight:bold;# }

    if we use then 1 part will work and after # if 2nd hack css code is mentioned then it wont work.. plz give me code for it.

    Get your own gravatar for comments by visiting gravatar.com
    Hiren Mehta
    July 10th, 7:23 am
  • The hack doesn’t work on the new Safari 3 beta. I tested the demo page on both Mac and Windows versions.

    Get your own gravatar for comments by visiting gravatar.com
    Jason Boychuk
    July 19th, 2:26 pm
  • Perhaps the hack is no longer even needed with the darling new beta release from Apple. But then again…

  • really good hack i’ve used sparingly in the past, but now I’m left searching for a hack for safari 3 on windows :( oh the joys of cross browser compatibility!

  • can any one explain, how to customize look & feel of form elements in Safari for mac? How to hide textfield border or change its color??
    Also is there anyway to hide the blue glow in mac for textfield??

  • Some belated responses here (I apologize for not reviewing these comments months earlier):

    Hiren, all styles after the # sign are ignored by Safari versions less than 3, so simply group all of your Safari only rules above the first # and you can override as many classes as you want.

    Jason and Chaz, you're correct—the hack no longer works in Safari 3. I added a disclaimer to the top of the post to make this more apparent.

    Chaz, there is a hack for Safari 3. I wrote about it here.

  • hi Jeffrey,

    is there anything make the text rendered in safari lighter and don’t look as if it’s bold?

    Thanks alot,

    Mohammed

  • Be careful with that hack :)

  • [...] by route609 any idea what the root hack is as the problem is only happening on versions < 2 Safari CSS hack | theMechanism, llc. [...]

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Search the Archives
Feeds

Upcoming events

  • 24 Jul 2008

O'Reilly user group program member

Add to Technorati Favorites

We endorse

Basecamp

Want to work with us yet? We’re ready when you are.