Safari doesn’t read inline css
Monday 02/9/2009 – Category: Uncategorized
I'm not sure why I haven't come across this until this past week, but I found out that Safari doesn't render css within style tags outside the head tags.
The workaround is to inject the style into the head with javascript--similar to what Rails' content_for does:
var cssDefinitions = '..my style chunk goes here'; var style = document.createElement('style');' $(style).html(cssDefinitions); $('head').append(style);
(jquery code from stackoverflow)
After this things were looking dandy in Safari but now IE was giving a weird "unexpected call to method or property access" error. It turns out that IE doesn't let you add style elements like this. The workaround for IE looks like this:
var styleElement = document.createElement("style"); styleElement.type = “text/css”; if (styleElement.styleSheet) { styleElement.styleSheet.cssText = “a { color: red }”; } else { styleElement.appendChild(document.createTextNode(”a { color: red; }”)); } document.getElementsByTagName(”head”)[0].appendChild(styleElement);
source: YUI blog
Leave a Reply
Recent Posts
- Marble Paint
(Friday 02/4/2011 – 1 Comment) - More Flickr Original Updates
(Sunday 01/23/2011 – 13 Comments) - Flickr Original updates
(Saturday 08/7/2010 – 19 Comments) - LED Light for iPhone 4
(Monday 06/28/2010 – 65 Comments)
