使用noscript嵌入额外的样式 [英] Embedding extra styles with noscript

查看:77
本文介绍了使用noscript嵌入额外的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XHTML严格的页面,有一个不可见的div,由Javascript控制。



当使用浏览器的人(或firefox的noscript)没有使用时,会将div设置为透明且可见的脚本和鼠标悬停事件。 javascript的div只是保持不可见。这个问题是我不想让内容无法访问。我也不想让div可见,然后使用脚本使它透明,因为div位于文档的底部,每当页面加载时会引起明显的闪烁。



我已经尝试使用noscript标签嵌入一个额外的样式表,只为没有豪华的Javascript的人加载,但这不能通过XHTML严格验证。在XHTML有效的noscript块中包含额外的样式信息是否还有其他方法?



Ed:



有了一个简单的测试用例,我得到一个验证错误:文档类型不允许元素style这里。
这是一个空的XHTML Strict文档在noscript元素内有一个样式元素。

要清除验证问题: noscript 只允许在 body 元素, style / code>。因此,后者不允许在前者之内。



在一般问题上:你需要使 div 元素默认可见,然后通过CSS + javascript隐藏。这是渐进增强模型。我注意到你说你不想这样做,因为闪烁,但我不知道是什么导致这 - - 可能是你可以解决它,所以也许你应该发布 作为一个问题。


I have an XHTML strict page that has an invisible div that is controlled by Javascript. The div is set to transparent and visible by the script and a mouseover event to make the div opaque on hover.

When someone using a browser (or firefox with noscript) without javascript the div simply remains invisible. The problem with this is that I do not want the content to be inaccessible. I also do not want to leave the div visible then use the script to make it transparent as the div is located at the bottom of the document and it causes a noticeable flicker whenever a page loads.

I have tried using noscript tags to embed an additional style sheet that is only loaded for people without the luxury of Javascript but this fails the XHTML strict validation. Is there any other way to include extra styling information inside a noscript block that is XHTML valid?

Ed:

With a simple test case I get a validation error of: document type does not allow element "style" here. This is with an empty XHTML Strict document with a style element inside a noscript element. The noscript is inside the body.

解决方案

To clear up the validation issue: noscript is only allowed in the body element, style only allowed in the head. Therefore, the latter is not allowed within the former.

On the general issue: you'll want to make the div element visible by default, then hide it via CSS + javascript. This is the 'progressive enhancement' model. I notice you say you "don't want to do this because of the flicker", but I'm not sure exactly what's causing this - chances are you can fix it, so maybe you should post that as a question.

这篇关于使用noscript嵌入额外的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆