jQuery可以修改特定媒体类型的CSS吗? [英] Can jQuery modify the CSS for a specific media type?

查看:248
本文介绍了jQuery可以修改特定媒体类型的CSS吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery是否可以修改特定媒体类型(例如print)的CSS?

Is it possible for jQuery to modify the CSS for a specific media type (e.g. print)?

我的具体问题是我对元素使用动画它覆盖了打印样式表,这会破坏我的打印布局。虽然我的问题与一般问题略有不同,我认为答案应该帮助我解决我的问题。任何可能的解决方法也将是有帮助的。很有必要。

My specific problem is that I'm using animate on an element and it's overriding the print stylesheet, which ruins my print layout. Though my problem is slightly different than the general question posed, I think an answer should help me resolve my problem. Any possible workarounds would be helpful also. Much obliged.

推荐答案

您不需要使用Javascript执行此操作。只需在您的css文档中使用 @media 规则。
你可以在一个css文件中写所有这些东西。以下是具体的 W3C文档

You don't need to do this with Javascript. Just use the @media rule in your css document. You can write all these stuff in only one css file. Here is the specific W3C Documentation

@media screen {

/* all your fancy screen css with a bunch of animation stuff*/

}

@media print {

/* all your fancy print css just plain */

}

您可以撰写非常具体的声明,并根据您的需要匹配所有元素。它支持下到IE6 。在我们的项目中像一个魅力。

You can write very specific declarations and match all elements to your needs. Btw it's supported down to IE6. Works like a charm in our projects.

@media print {
   body { font-size: 10pt }
}

@media screen {
   body { font-size: 13px }
}

@media screen, print {
   body { line-height: 1.2 }
}

这篇关于jQuery可以修改特定媒体类型的CSS吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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