Hacked to Death ii (Safari)

October 8th, 2006

Apologises for the lack of posts the last few days. I’ve not been on holiday, far from it, I’ve started a new contract. I will be producing for a leading media company.

This actually brings me nicely onto this blog entry’s topic - Hacking Safari. I am used to testing on the major PC based browsers (FireFox, IE, Opera and to a lesser extent Mozilla, Netscape, linx) but have never been required or had the hardware to test with Macintosh’s Safari.

For the most part if a design works in FF and IE, Safari will quite happily play along. However, on one page where I have used relative positioning to move an image up by a few pixels I encountered a problem. FF and IE6 didn’t line up. I was forced to use an IE6 hack (see previous hacked to death entry) to set a different pixel adjust for the two browsers. While this solved the problem in IE6, Opera, FF and IE7 - Safari was not happy.

While Safari had rendered the page as FF it treated the positioning of this image as IE6. As IE6 hack only affects IE6 and older Safari’s positioning of he image is not corrected. Quiet a problem.

Thus began my quest to find a CSS hack that only affected Safari. Preferably an elegant hack (if there is such a thing) still allowed my style sheet to validate and would not affect future versions of The browser.

I wish I could tell you I’d found a solution. So fa the only option I can verify works is the ugliest hack ever. It requires you to add a hash just before the closing bracket of the style you want to hack. The style has to be written on a single line (see example below). What this does is cause Safari to escape from the style sheet completely.

This means any styles following this will be read by other browsers but ignored by Safari.

This means your hack has to go at the very end of the style sheet. You will need to put the safari friendly style first (Including the hash hack) then the IE friendly style and finally the style for all other browsers (using the child selector - see example below).

This hack can only be used on 1 style per style sheet. If you need more than 1 Safari hack you need multiple style sheets.

This is a far from ideal so my quest for a better Safari hack continues. For now I’d say using an alternative way of positioning an item or redesigning a page would be preferable than using this hack. My search for a better hack continues.

=Dave Long=

Have your say?

Comments welcome - you don't have to agree :)

Name (required)

Email (required)

Website


Speak your mind

Trackback URL | Comments RSS

    About

    Although originally designed to document my work and new web development tricks I learnt it has expanded to cover tech and news that I find interesting so in addition to tutorials and interviews expect to see product reviews and tech news too. If you enjoy please comment. David

    Blogroll
    • Adele Kirby - Freelance Writer and most chipper/perky person alive
    • Alex Pullin - Freelance Tech Writer and former PR queen
    • Display: Block - Blog of fellow developer Savell Martin
    • Molly E. Holzschlag - Web standards advocate and Genious
    • Nate Laxon - Funny guy and music guru
    • Paul Boag - Helping website owners and promoting webstandards. The King of Web Design Podcasts
    • Poached Online - news/current affairs/political comment: no eggs
    • Tale of 2 Blogs - Blog about my other blogs
    Admin
  • From Display:Block
    • SpringWidgets
      RSS Reader
      This widget is the staple of our platform. Read all your feeds right here with this one widget - Supported feeds are OPML, RSS, RDF, ATOM. Watch your favorite Podcast in the embedded Video Player on the Desktop or publish your own video playlist to your site for others to view!
      Visit the Widget Gallery