It\'s very strange,but still work.

相关标签:
5条回答
  • 2021-01-07 23:20

    It's worth pointing out that although it's invalid HTML, it's also extremely common, and any browser that didn't support it would fail to render properly a significant portion of the web.

    Mash-ups in particular, need use of this feature, and HTML 5 defines <style scoped> to deal with this use case. <style scoped> can appear in the body, though styles so defined do not apply to the whole document, only to the section in which <style scoped> appears.

    WARNING: HTML 5 is a draft, and there is no guarantee that <style scoped> or any other HTML 5 feature that is not already implemented will ever be implemented.

    0 讨论(0)
  • 2021-01-07 23:35

    In HTML5, a <style> tag is allowed to appear under anything in <body> or <head>.

    Mostly you are not allowed to put blocking elements into inline elements but meta elements like style, script, meta may appear wherever you want.

    0 讨论(0)
  • 2021-01-07 23:37

    The STYLE element is only allowed as child of the HEAD element. See this explanation for further details.

    0 讨论(0)
  • 2021-01-07 23:39

    I found an example where the tag inside a div is not read correctly by IE8 (it works fine in Firefox and Chrome) I can't reproduce it with a simple example because I don't know where the problem is. But if I move the outside the div everything works again. Why I'm using a tag inside a div? because I'm loading external data with AJAX inside that div, and I don't know other way to add the styles in that situation.

    0 讨论(0)
  • 2021-01-07 23:42

    Yes, it violates the HTML specification.

    <!ELEMENT DIV - - (%flow;)*            -- generic language/style container -->
    

    (from the div section of the specification)

    Follow the hyperlinks in the live version if you want to see exactly how %flow; expands (it doesn't include style).

    Browsers just tend to do huge amounts of error recovery because so many authors do stupid things.

    Don't depend on error recovery — there are lots of browsers out there, and they don't all behave the same way when the HTML doesn't conform to spec.

    0 讨论(0)
提交回复
热议问题