问题
i have very weird problem. If i put style or script tag on page, the browser sees them as html elements. In other words they are displayed, printed on page physically. Bottom code is shown in browser, on page, when i start my project. Any suggestions?
回答1:
In your CSS code, you probably set display: inline-block
on head
, style
, and script
elements, possibly due to the use of the universal selector *
. By default, those elements are not displayed (they have implied display: none
), but on many browsers, this can be changed with CSS. It’s normally not useful, but possible.
回答2:
Just manually add inline display: none
to those tags.
That would make it work.
Like, make your <script>
like this:
<script type="text/javascript" style="display: none">
//Some JS here
</script>
and <style>
as
<style type="text/css" style="display: none">
/* Some CSS */
</style>
Works pretty much on every browser (including IE8), not the best way since if they are being displayed, it means your CSS has some hole in it.
回答3:
Validate your page for unclosed tags: http://validator.w3.org/
来源:https://stackoverflow.com/questions/18182211/style-and-script-tags-are-displayed-physically-on-page