- From: Jukka K. Korpela <jkorpela@cs.tut.fi>
- Date: Fri, 25 Mar 2011 11:17:50 +0200
Boris Zbarsky wrote: > On 3/24/11 9:29 PM, Nicholas Zakas wrote: [...] >> Fixing the issue results in: >> >> <div> >> <style scoped>.foo { color: red; }</div> >> </div> > > The correct fix for this issue is to put this <style> in the <head>, > isn't it? Why would would you fix it by adding @scoped? There is nothing wrong with the markup as far as current HTML5 drafts are considered, but it has a meaning different from the intended one. The obvious use case for <style scoped> is in situations where you insert elements taken from an external source into, say, a blockquote or article element and wish to preserve their formatting as in the original (more or less). Modification of the style sheet would be another way of doing it, but often rather awkward. By the way, W3C Markup Validator currently has its own views on where <style scoped> is allowed. For example, it does not allow it as the first child of <body>. The use case for <style> inside the document body without the scoped attribute is quite different, typically in situations where the document is being generated programmatically and when generating content, some style settings should be inserted (perhaps something that cannot be handled using style="..." attributes). There are even situations - more often than many people would want - where an author can only affect the <body> element. So putting a <style>, meant to be global, in the <head> simply isn't an option in many cases. Maybe such cases shouldn't exist, but they do. There's a fundamental compatibility issue with <style scoped>. Existing browsers simply ignore the scoped attribute and apply the styles to the entire document. This is surely not what an author means when he uses <style scoped> as per HTML5. Suggestion: Drop <style scoped>. Instead, introduce a new attribute, say styleref, which is permitted for elements that allow flow content, or for any element (whichever is easier). The attribute would specify a space-separated list of CSS stylesheet URLs, to be applied inside the element. Benefits: - old browsers ignore it, instead of wrongly applying styles globally - the <style> element preserves its semantics unchanged; whether it is to be allowed inside <body> can be decided separately (my suggestion would be that it be described as conforming but obsolete feature) - the typical use case of <style scoped> involves external documents with their own stylesheets rather than something you can conveniently cut and paste - external stylesheets should generally be favored over embedded, and at least there should be an option of using an external stylesheet. -- Yucca, http://www.cs.tut.fi/~jkorpela/
Received on Friday, 25 March 2011 02:17:50 UTC