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

浪子不回头ぞ 提交于 2020-01-24 21:19:05

问题


I'm starting out with phonegap and have found the docs to be a bit vauge on this point.

When I use insertCSS() on my current project it seems like whatever path I use, the css is not used.

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.

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.

What am I missing?


回答1:


Internal type styling in CSS generally have a higher order of precedence over external styling.

Therefore This (from your GitHub Code):

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)


来源:https://stackoverflow.com/questions/23036804/what-should-file-paths-fed-to-insertcss-be-relative-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!