简体   繁体   English

馈给insertCSS()的文件路径应相对于什么?

[英]What should file paths fed to insertCSS() be relative to?

I'm starting out with phonegap and have found the docs to be a bit vauge on this point. 我从phonegap开始,发现这方面的文档有些夸张。

When I use insertCSS() on my current project it seems like whatever path I use, the css is not used. 当我在当前项目上使用insertCSS() ,无论使用什么路径,都不会使用css。

As you can see from that link, my file structure is: 从该链接可以看到,我的文件结构是:

app-root
|
...
|_ www
    |
    |_ css
    |   |
    |   target.css
    |
    |_ js
    |   |
    |   index.js
    |   
    index.html

In index.js I'm making a call to insertCSS() in the event listener for an inAppBrowser. 在index.js中,我正在inAppBrowser的事件侦听器中调用insertCSS()。

This function should be pulling target.css: 这个函数应该拉目标:

iab.addEventListener('loadstop', function() {
    // Once loaded, add css
    iab.insertCSS( { file: "target.css" } );
});

But... it doesn't 但是...没有

I've tried multiple different relative file paths like css/target.css and ../css/target.css but they don't seem to work. 我尝试了多个不同的相对文件路径,如css/target.css../css/target.css但它们似乎不起作用。

What am I missing? 我想念什么?

Internal type styling in CSS generally have a higher order of precedence over external styling. CSS中的内部类型样式通常比外部样式具有更高的优先级。

Therefore This (from your GitHub Code): 因此,这(从您的GitHub代码):

iab.insertCSS( { code: "body { background-color: green; }" }, function(){
  iab.insertCSS( { code: "body { background-color: green; }" } );

would always be executed instead of this: 将始终执行而不是执行以下操作:

iab.insertCSS( { file: "../css/chat.window.css" }

since they are both styling the same element. 因为它们都在样式相同的元素。 The complete order of precedence from top priority to least is: 从最高优先级到最低优先级的完整优先顺序为:

  1. Inline Style (top priority) 内联样式(最高优先级)
  2. Internal Style 内部风格
  3. External Style (least priority) 外部风格(最低优先级)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM