Can I use an HTML <style> element without line-breaks?
<style>/* foo */ body{color:red}div{color:green}</style>
So, I have this <style>
element. It has a comment, and then several CSS rules. It is my CSS reset code, so I would like to have it in one line, without a single line break inside the <开发者_JAVA技巧;style>
element.
Is this OK with browsers?
Sure it is. Whitespace is insignificant in CSS except in at-rules, as the descendant combinator, and when using it to separate property values (e.g. in shorthand properties), among other things.
The CSS2.1 syntax documentation talks about the effect of whitespace (or lack thereof) on your CSS code.
Yes (provided you include proper attributes on your <style>
element :).
精彩评论