如果未启用javascript,请定义css [英] Define css if javascript is not enabled

查看:74
本文介绍了如果未启用javascript,请定义css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果未启用javascript,我想定义 .exampleclass img {height:250px} 。他们无论如何要在javascript / jquery中撤消这个?

I want to define .exampleclass img {height:250px} if javascript is not enabled. Is their anyway to undo this in javascript / jquery?

推荐答案

您可以使用HTML的 noscript 标记。

You could probably use HTML's noscript tag.

<noscript>
    <style type="text/css">
        .exampleclass img {height:250px}
    </style>
</noscript>






编辑:我实际上,斯蒂芬的答案是最好的。虽然上述方法可能有效,但可能无效/遵循最佳做法。


EDIT: I'm going to actually side with Stephen's answer as being the best. While the above might work, it might not be valid/following best practices.

Stephen回答:

Stephen answered:


在你的body元素上放一个no-js类,然后在加载时用JS删除它,并在CSS的选择器中使用.no-js

put a "no-js" class on your body element, and then remove it with JS at load, and use .no-js in the selector for your CSS

该类也可以放在你的 html 元素上,然后当JavaScript不可用时应该出现的所有样式都可以以 html.no-js 为前缀,否则选择器将会出现。例如, HTML5 Boiler Plate 就是这样做的。

The class could also be placed on your html element and then all styling that should appear when JavaScript is not available can be prefixed with html.no-js before what the selector would be otherwise. This is what HTML5 Boiler Plate does, for example.

这篇关于如果未启用javascript,请定义css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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