noscript 标签的正文样式?

发布于 2024-10-04 11:07:22 字数 127 浏览 1 评论 0 原文

如果没有启用 JavaScript,我希望我的正文具有 overflow:hidden (无滚动条)。

我该如何解决这个问题?是否可以在 内部使用 noscript 标记?并在里面设置特定的样式?

If no JavaScript is enabled, I want my body to have overflow:hidden (no scrollbars).

How can I solve this? Is it possible to use a noscript tag inside of <head> and set specific styles inside of it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

魂归处 2024-10-11 11:07:22

如果您指的是 HTML 文档的 ,我会为禁用 JS 的用户构建 HTML。例如,在 CSS 文件中包含 body { Overflow:hidden },然后使用 JavaScript 设置页面,因为它应该适合启用 JavaScript 的用户(即删除 overflow:hidden > 使用 JavaScript)。

If you mean the <body> of the HTML document, I'd build the HTML as it should be for the users with JS disabled. For example in the CSS file have body { overflow:hidden } and then use JavaScript to set the page as it should be for users with JavaScript enabled (i.e. remove the overflow:hidden with JavaScript).

暮色兮凉城 2024-10-11 11:07:22

我非常确定

<noscript>
    <style type="text/css">
        body {
            overflow:hidden;
        }
    </style>
</noscript>

您的 可以完成这项工作。

但正如另一篇文章中所述,最好使用 CSS 来实现此目的,并使用 JavaScript 为浏览器启用溢出。

I'm pretty sure

<noscript>
    <style type="text/css">
        body {
            overflow:hidden;
        }
    </style>
</noscript>

in your <head> would do the job.

But as stated in the other post, it may be better to use CSS for this purpose, and enable overflow for browsers with JavaScript.

流年已逝 2024-10-11 11:07:22

在 head 部分内使用

 <!doctype html>
 <html lang="en">
     <head>
         <script>document.documentElement.className = 'js';</script>
         <style>
             body { overflow: hidden; }
             html.js body { overflow: auto; }
         </style>
     </head>

It's not valid using the <noscript> tag inside the head section (it is allowed only inside <body>), so you could use this workaround instead (an HTML5 example)

 <!doctype html>
 <html lang="en">
     <head>
         <script>document.documentElement.className = 'js';</script>
         <style>
             body { overflow: hidden; }
             html.js body { overflow: auto; }
         </style>
     </head>
恰似旧人归 2024-10-11 11:07:22

这可能是一个超级杀伤力,但只是为了一般知识:

Modernizr 使用一种机制,建议您将 < code>no-js 类在你的 html 标签上。如果 Modernizr 运行,它会删除 no-js 类。使用 Modernizr 有点大材小用,但你可以自己做。在你的 css 中你会有:

html.no-js body {
    overflow:hidden;
}

This is probably a super overkill, but just for general knowledge:

Modernizr uses a mechanism where it suggest you put the no-js class on your html tag. If modernizr runs, it removes the no-js class. Using modernizr would be an overkill, but you could do this yourself. In your css you would have:

html.no-js body {
    overflow:hidden;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文