问题
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:
- Inline Style (top priority)
- Internal Style
- External Style (least priority)
来源:https://stackoverflow.com/questions/23036804/what-should-file-paths-fed-to-insertcss-be-relative-to