【发布时间】:2012-03-08 16:52:39
【问题描述】:
我有一个使用 XHTML 过渡的文档。在正文中,我使用带有<style type="text/css"> 的<noscript> 标签。
我知道 <style type="text/css"> 只允许在 <head> 中使用,但我仍然需要仅在未检测到 JavaScript 时应用 CSS。
如何在通过 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]
【问题讨论】:
-
<noscript>不允许在<head>中吗? :) -
您可以尝试其他方式:默认使用此样式表并使用 JavaScript 使其可见。
-
嗨 Stefan,对不起,我忘了在我的问题中写
-
@Stefan — 不,不是(至少在 XHTML 1.0 过渡版中没有)。
-
见@Quentin 回答的stackoverflow.com/questions/4902658/…
标签: javascript html xhtml w3c-validation