XHTML 文档类型不允许使用元素“style”在体内

发布于 2025-01-06 17:09:44 字数 898 浏览 9 评论 0原文

我有一个使用 XHTML Transitional 的文档。在正文中,我使用 标记和

如何解决这个问题,同时仍然通过 XHTML 验证?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
  <noscript>
    <div id="section-featured-nojavascript" class="section">
      <style type="text/css">
        #featured, #section-portfolio { display:none; visibility:hidden }
      </style>
    </div>
  </noscript>
</body>

使用 W3 验证时出错

document type does not allow element "style" here [XHTML 1.0 Transitional]

I have a document using XHTML Transitional. In the body I use a <noscript> tag with a <style type="text/css">.

I know that <style type="text/css"> is only allowed in the <head>, but still I need to have the CSS applied only if JavaScript isn't detected.

How can I solve this problem, while still passing XHTML validation?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
  <noscript>
    <div id="section-featured-nojavascript" class="section">
      <style type="text/css">
        #featured, #section-portfolio { display:none; visibility:hidden }
      </style>
    </div>
  </noscript>
</body>

ERROR when validation using W3

document type does not allow element "style" here [XHTML 1.0 Transitional]

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

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

发布评论

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

评论(3

痕至 2025-01-13 17:09:44

不要尝试拥有单独的样式表。使用 JS 将 js 类添加到 中(或删除 no-js 类)。然后将其用作主样式表中的后代选择器的一部分。

Don't try to have a separate stylesheet. Use JS to add a js class to the <body> (or to remove a no-js class). Then use that as part of a descendent selector in your main stylesheet.

橘味果▽酱 2025-01-13 17:09:44

你可以

#featured, #section-portfolio { display:none; visibility:hidden }

在你的css中设置默认值并用javascript“撤消”它吗?

来自 w3schools:
noscript 标记用于为在浏览器中禁用了脚本或拥有不支持客户端脚本的浏览器的用户提供替代内容。

noscript 元素可以包含您可以在普通 HTML 页面的 body 元素中找到的所有元素。

仅当不支持脚本或在用户浏览器中禁用脚本时,才会显示元素内的内容。

You could set

#featured, #section-portfolio { display:none; visibility:hidden }

by default in your css and "undo" it with javascript?

From w3schools:
The noscript tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.

The noscript element can contain all the elements that you can find inside the body element of a normal HTML page.

The content inside the element will only be displayed if scripts are not supported, or are disabled in the user’s browser.

第几種人 2025-01-13 17:09:44

您可以尝试使用 javascript 更改 css 文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>What ever</title>
<link rel="stylesheet" type="text/css" href="scripting_off.css"  id="client_side_scripting"/>
<script  type="text/javascript">
document.getElementById('client_side_scripting').setAttribute('href','scripting_on.css');
</script>
</head>
<body>

</body>
</html>

You could try changing the css file using javascript:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>What ever</title>
<link rel="stylesheet" type="text/css" href="scripting_off.css"  id="client_side_scripting"/>
<script  type="text/javascript">
document.getElementById('client_side_scripting').setAttribute('href','scripting_on.css');
</script>
</head>
<body>

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