是否可以使用另一个样式表对div(及其子项)进行样式化? [英] Is it possible to style a div (and its children) with another stylesheet?

查看:93
本文介绍了是否可以使用另一个样式表对div(及其子项)进行样式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示一个打印预览div( #preview 在示例中)。有没有办法使用 print.css 仅用于特定的div及其子元素覆盖所有本地定义?

I'm trying to show a print-preview div (#preview in examples). Is there a way to use print.css only for a particular div and its children overriding all local definitions?

基本上,我想能够做类似的事情:

Essentially, I would like to be able to do something similar to:

#preview element {
    definition equal to definition of an element in print.css
}

中的元素的一个元素定义列表。

in main.css, but for a long list of definitions. It's not too DRY and following option is more coherent.

第二种方法是将 print.css 加入主文档并更改每个定义

Second approach would be to include print.css into the main document and change each definition from

element {
    definition
}

到:

element, #preview element {
     definition
}

笨重。

解决此问题的最佳方法是什么?

But that seems to me a bit cumbersome.
What would be the best way to solve this problem?

更新只是举例: br>
在主文档中我有红色下划线的链接,他们应该是蓝色未装饰的打印版本。所以当预览的内容动态形成时,我弹出div,其中所有的链接应该是蓝色的无装饰。但是只有那个特定的div( #preview ),在文档的其余部分,它们仍然是红色和下划线。

Update just to give an example:
in the main document I have red underlined links, they should be blue undecorated in print version. So when content of preview is dynamically formed, I pop up div where all links should be blue undecorated. But only in that particular div (#preview), in the rest of the document they still would be red and underlined.

推荐答案

也许我还是没有抓住你的问题,但似乎你应该能够通过简单的链接print.css样式表在你的主样式表后,

Maybe I still haven't grasped your question, but it seems you should be able to do this by simply linking the print.css stylesheet after your main stylesheet, and prefixing all the selectors in print.css with "#preview ".

在链接示例中,您需要指定一个样式:

In the links example, you would need to specify a style like:

#preview a, #preview a:link 
{
    text-decoration:none;
    color:blue;
}

这应该很简单,除非你动态创建print.css文件。

This should be pretty simple unless you are dynamically creating the print.css file.

这篇关于是否可以使用另一个样式表对div(及其子项)进行样式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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