Comments on: Who’s Got Style? http://yuiblog.com/blog/2007/06/07/style/ News and Artilces about Designing and Developing with Yahoo! Libraries. Sat, 26 Jul 2008 23:54:09 +0000 http://wordpress.org/?v=2.3.3 By: Shlomi Rosenzweig http://yuiblog.com/blog/2007/06/07/style/#comment-388010 Shlomi Rosenzweig Mon, 02 Jun 2008 17:37:05 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-388010 You can also add style sheets using a similar function: function addCssFile(css) { var styleElement = document.createElement("link"); styleElement.type = "text/css"; styleElement.rel="stylesheet"; styleElement.href = css; document.getElementsByTagName("head")[0].appendChild(styleElement); } You can also add style sheets using a similar function:

function addCssFile(css) {
var styleElement = document.createElement(”link”);
styleElement.type = “text/css”;
styleElement.rel=”stylesheet”;
styleElement.href = css;
document.getElementsByTagName(”head”)[0].appendChild(styleElement);
}

]]>
By: .wpal » Blog Archives » Кто получил стиль? http://yuiblog.com/blog/2007/06/07/style/#comment-151871 .wpal » Blog Archives » Кто получил стиль? Wed, 04 Jul 2007 08:02:19 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-151871 [...] Who’s Got Style? Posted in перевод, wtf, javascript, программирование | Trackback | [...] […] Who’s Got Style? Posted in перевод, wtf, javascript, программирование | Trackback | […]

]]>
By: Añadir CSS dinámicamente en tu web « Jery Rojas - Diseñador Web http://yuiblog.com/blog/2007/06/07/style/#comment-140436 Añadir CSS dinámicamente en tu web « Jery Rojas - Diseñador Web Thu, 14 Jun 2007 05:36:08 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-140436 [...] CSS dinámicamente en tu web En el Yahoo! User Interface Blog, hace unos días, publicaron un interesante artículo sobre como, con DOM, añadir CSS [...] […] CSS dinámicamente en tu web En el Yahoo! User Interface Blog, hace unos días, publicaron un interesante artículo sobre como, con DOM, añadir CSS […]

]]>
By: Jesse Skinner http://yuiblog.com/blog/2007/06/07/style/#comment-139555 Jesse Skinner Tue, 12 Jun 2007 10:37:15 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-139555 Regarding why you might want to add style blocks using JavaScript: I've worked on a web site builder that allowed users to dynamically change the look of links on the page (and other things), so we needed to be able to throw a style block on the page containing: a { color: #F82156; text-decoration: none } a:visited { color: #752007; } a:hover { text-decoration: underline } For this and similar situations, adding script blocks is a great solution. Regarding why you might want to add style blocks using JavaScript: I’ve worked on a web site builder that allowed users to dynamically change the look of links on the page (and other things), so we needed to be able to throw a style block on the page containing:

a { color: #F82156; text-decoration: none }
a:visited { color: #752007; }
a:hover { text-decoration: underline }

For this and similar situations, adding script blocks is a great solution.

]]>
By: Intenta » Blog Archive » Añadir CSS dinámicamente en tu web http://yuiblog.com/blog/2007/06/07/style/#comment-139065 Intenta » Blog Archive » Añadir CSS dinámicamente en tu web Mon, 11 Jun 2007 09:27:36 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-139065 [...] el Yahoo! User Interface Blog, hace unos días, publicaron un interesante artículo sobre como, con DOM, [...] […] el Yahoo! User Interface Blog, hace unos días, publicaron un interesante artículo sobre como, con DOM, […]

]]>
By: Around the web | alexking.org http://yuiblog.com/blog/2007/06/07/style/#comment-138593 Around the web | alexking.org Sun, 10 Jun 2007 14:58:29 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-138593 [...] Who’s Got Style? Yahoo! User Interface Blog - I ran into this when I started building widgets. [...] […] Who’s Got Style? Yahoo! User Interface Blog - I ran into this when I started building widgets. […]

]]>
By: Oliver Tse http://yuiblog.com/blog/2007/06/07/style/#comment-137687 Oliver Tse Fri, 08 Jun 2007 18:51:27 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-137687 Nicholas, Thanks for the clarification. I agree. I think this is why we should use toolkits and libraries. A similar problem exists with dynamic script tags -- <a href="http://skypoetsworld.blogspot.com/2007/05/on-demand-javascript-ie67-and-firefox.html" rel="nofollow">Dynamic Script Tags</a> Oliver Nicholas,

Thanks for the clarification. I agree. I think this is why we should use toolkits and libraries.

A similar problem exists with dynamic script tags — Dynamic Script Tags

Oliver

]]>
By: Nicholas C. Zakas http://yuiblog.com/blog/2007/06/07/style/#comment-137646 Nicholas C. Zakas Fri, 08 Jun 2007 16:52:02 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-137646 To those would pointed out that the HTML spec says all style elements should be in the head of the document, you are correct. The point I was trying to make is that when a browser makes an exception in one direction it seems odd that it doesn't make an exception in the other. Why would style tags included inside of the body work when dynamically created style tags placed inside of the body do not? This is what makes our profession so interesting (fun?). @Ross - The maintainability aspect is from the separation of JavaScript and CSS, as described in my talk. Victor pointed out that using this function would require embedding of CSS into your JavaScript code. However, that doesn't have to be case. You can retrieve the CSS via XHR and insert it into the page using this function. That way, the CSS and JavaScript are separated and you are able to dynamically load styles (which becomes necessary more frequently these days) with all the bells and whistles of other XHR requests. To those would pointed out that the HTML spec says all style elements should be in the head of the document, you are correct. The point I was trying to make is that when a browser makes an exception in one direction it seems odd that it doesn’t make an exception in the other. Why would style tags included inside of the body work when dynamically created style tags placed inside of the body do not? This is what makes our profession so interesting (fun?).

@Ross - The maintainability aspect is from the separation of JavaScript and CSS, as described in my talk. Victor pointed out that using this function would require embedding of CSS into your JavaScript code. However, that doesn’t have to be case. You can retrieve the CSS via XHR and insert it into the page using this function. That way, the CSS and JavaScript are separated and you are able to dynamically load styles (which becomes necessary more frequently these days) with all the bells and whistles of other XHR requests.

]]>
By: ross http://yuiblog.com/blog/2007/06/07/style/#comment-137616 ross Fri, 08 Jun 2007 15:23:51 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-137616 Interesting article, but I have a small nit to pick. You say: "This block of code [style block] can be placed anywhere in a page ..." According to the HTML 4.01 spec section 14.2.3, style tags must be contained in the head element: "HTML permits any number of STYLE elements in the HEAD section of a document." Link to the spec: http://www.w3.org/TR/html401/present/styles.html#edef-STYLE I'm not sure what the browser support is for style blocks defined outside the head (most likely it works fine), but there's no reason not to stick to the spec -- append the style block to the head, as you do in the Safari example. Also, a comment: I don't really see the maintainability benefit of this technique. If you compress/minify your CSS and allow the browser to download and apply it, what would the benefit of dynamically creating styles be? I don't mean to be negative, the article is well-written and makes some interesting points. Interesting article, but I have a small nit to pick.

You say: “This block of code [style block] can be placed anywhere in a page …”

According to the HTML 4.01 spec section 14.2.3, style tags must be contained in the head element: “HTML permits any number of STYLE elements in the HEAD section of a document.”

Link to the spec:
http://www.w3.org/TR/html401/present/styles.html#edef-STYLE

I’m not sure what the browser support is for style blocks defined outside the head (most likely it works fine), but there’s no reason not to stick to the spec — append the style block to the head, as you do in the Safari example.

Also, a comment:
I don’t really see the maintainability benefit of this technique. If you compress/minify your CSS and allow the browser to download and apply it, what would the benefit of dynamically creating styles be?

I don’t mean to be negative, the article is well-written and makes some interesting points.

]]>
By: Oliver Tse http://yuiblog.com/blog/2007/06/07/style/#comment-137601 Oliver Tse Fri, 08 Jun 2007 14:12:38 +0000 http://yuiblog.com/blog/2007/06/07/style/#comment-137601 In my last post, I munged up my response... Here's the complete response. Thanks for the information regarding IE, but I think the style tag would always be in the head tag not outside of it. The Safari implementation is correct. Even if you leave Safari out, I think putting the style tag outside of the head will not work in strict mode. The YUI blog is informative and great. In my last post, I munged up my response… Here’s the complete response.

Thanks for the information regarding IE, but I think the style tag would always be in the head tag not outside of it. The Safari implementation is correct.

Even if you leave Safari out, I think putting the style tag outside of the head will not work in strict mode.

The YUI blog is informative and great.

]]>