仅当用户启用JavaScript时,才使用一些CSS [英] Use some CSS only if user has JavaScript enabled

查看:65
本文介绍了仅当用户启用JavaScript时,才使用一些CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了让我的网页正常降级,我有一些CSS,应该只有在相应的JavaScript函数才能加载。

In order for my webpage to degrade gracefully, I have some CSS that should only be loaded if its corresponding JavaScript will function.

加载的最简单的方法是什么如果且仅当浏览器启用了JavaScript时,本地CSS?

What is the simplest way to load local CSS if and only if the browser has JavaScript enabled?

也是相当大的CSS块,所以我不想写一个JavaScript行每个属性。 (哦,如果需要我可以使用jQuery)。

Also it's quite a big block of CSS, so I'd rather not have to write a JavaScript line to add each attribute. (Oh, and if necessary I can use jQuery).

推荐答案

在noJS的body标签上设置一个类。

Set a class on the body tag of "noJS". Then use Javascript to remove that class.

对于没有JS的情况下使用的CSS规则,只需使用 .noJS。 myRules {}

For the CSS rules that you want to be used when no JS is present, just use .noJS .myRules {}

这篇关于仅当用户启用JavaScript时,才使用一些CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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