XHTML 文档类型不允许使用元素“style”在体内
我有一个使用 XHTML Transitional 的文档。在正文中,我使用 标记和
。
我知道 只允许在
中使用,但我仍然需要仅在以下情况下应用 CSS未检测到 JavaScript。
如何解决这个问题,同时仍然通过 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要尝试拥有单独的样式表。使用 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 ano-js
class). Then use that as part of a descendent selector in your main stylesheet.你可以
在你的css中设置默认值并用javascript“撤消”它吗?
来自 w3schools:
noscript 标记用于为在浏览器中禁用了脚本或拥有不支持客户端脚本的浏览器的用户提供替代内容。
noscript 元素可以包含您可以在普通 HTML 页面的 body 元素中找到的所有元素。
仅当不支持脚本或在用户浏览器中禁用脚本时,才会显示元素内的内容。
You could set
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.
您可以尝试使用 javascript 更改 css 文件:
You could try changing the css file using javascript: