I see something like this:
<div>
<style type="text/css">
...
</style>
</div>
It's very strange,but still work.
Is this against the standard?
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.
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.
The STYLE
element is only allowed as child of the HEAD
element. See this explanation for further details.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With