我想将 CSS 文件中的规则应用于某个 div/类,例如,events.css 的内容仅应用于名为 .events 的类的内容,而不是超出此范围而不需要将类 .events 添加到每个 css 规则的开头。
虽然我认为这是不可能的 - 但你永远不会知道。
如果不是,我正在考虑通过在上传/编辑后将 .events 添加到 CSS 规则的前缀来实现相同的效果。我认为这应该是相当没有问题的,但是有人预见到任何问题吗?
最佳答案
I am thinking this is not possible though
的确如此。除非您将相关内容放在 iframe 中。然后你会得到一个完整的单独文档,以不同的方式设置样式。
I am thinking of achieving the same effect by prefixing the .events to the CSS rules after they have been uploaded/edited. I am thinking this should be fairly trouble-free, but does anyone forsee any problems?
以自动化方式?您需要能够解析 CSS 输入以确定选择器的开头位置。
这并不像您想象的那样微不足道:
/* This is my grate CSS
.sausage { color: red; } adds a class rule
/*/ .eggs, .bacon { color: red; }
.potato:before { content: "; }
.beans { content: "; }
是一个难以解析的 CSS 示例。 .eggs
、.bacon
和 .potato
开始选择器并需要一个 .events
前缀。 .sausage
和 .beans
不是。
关于php - CSS 中的命名空间/作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1432306/