为特定DIV加载外部CSS [英] Load an external CSS for a specific DIV

查看:112
本文介绍了为特定DIV加载外部CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以基本上我有一个页面,它有自己的CSS。在我的服务器上,我有一个不同的CSS样式文件的文件夹,所以我想在他的页面上有一个预览窗口。我可以以某种方式,也许使用javascript,应用外部CSS文件只有一个特定的DIV,而不是整个页面,所以我可以得到一个预览的自定义CSS文件?

So basically I have a page that has it's own CSS. On my server I have a folder of different CSS style files, so I want to have a "preview" window on my page for them. Can I somehow, maybe using javascript, apply an external CSS file only to a certain DIV, not to the entire page so I can get a "preview" of the custom CSS file? I'd rather not use iframes.

推荐答案

CSS适用于整个文档。

CSS applies to entire documents.

如果您想限制范围,则需要使用后代选择器。

If you want to limit the scope, then you need to make use of a descendent selector.

例如 #id_of_div .the .rest .of .selector {}

您必须将此选项应用于每个选择器,并考虑(因此,它不是简单,只是前置整个样式表和后缀每个}

You have to apply this to every selector, and take into account groups (so it isn't as simple as just prefixing the whole stylesheet and suffixing every })

您还可以找到适用于您的预览的主文档的样式表。

You would also find the stylesheet for the main document applying to your preview.

一个框架可能是解决这个问题的最佳方法。

A frame would probably be the best approach to solving this problem.

这篇关于为特定DIV加载外部CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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