<style> and <script> tags are displayed physically on page

☆樱花仙子☆ 提交于 2019-12-21 17:15:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!