CSS <style> 和 <script> 标签实际显示在页面上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18182211/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:54:44  来源:igfitidea点击:

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

csstags

提问by user1797770

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?

我有很奇怪的问题。如果我在页面上放置样式或脚本标签,浏览器会将它们视为 html 元素。换句话说,它们被显示,物理打印在页面上。当我开始我的项目时,底部代码显示在浏览器的页面上。有什么建议?

enter image description here

在此处输入图片说明

回答by Jukka K. Korpela

In your CSS code, you probably set display: inline-blockon head, style, and scriptelements, 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.

在您的 CSS 代码中,您可能设置display: inline-blockheadstylescript元素,这可能是由于使用了通用选择器*。默认情况下,这些元素不会显示(它们已隐含display: none),但在许多浏览器上,这可以通过 CSS 进行更改。它通常没有用,但可能。

回答by J D

Just manually add inline display: noneto those tags. That would make it work.

只需手动将内联添加display: none到这些标签中。那将使它起作用。

Like, make your <script>like this:

就像,让你<script>像这样:

<script type="text/javascript" style="display: none">
    //Some JS here
</script>

and <style>as

并且<style>作为

<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.

几乎适用于所有浏览器(包括 IE8),这不是最好的方式,因为如果显示它们,则意味着您的 CSS 中存在一些漏洞。

回答by keaukraine

Validate your page for unclosed tags: http://validator.w3.org/

验证您的页面是否有未关闭的标签:http: //validator.w3.org/