提交给insertCSS()的文件路径应该是相对的? [英] What should file paths fed to insertCSS() be relative to?

查看:406
本文介绍了提交给insertCSS()的文件路径应该是相对的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我使用 insertCSS()时, )我当前的项目看起来像什么路径我使用,css不使用。



正如你可以从该链接看到的,我的文件结构是:

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

在index.js中我调用insertCSS在inAppBrowser的事件监听器中。



此函数应该拉target.css:

  iab.addEventListener('loadstop',function(){
//加载后,添加css
iab.insertCSS({file:target.css});
});

但不是



我尝试过多种不同的相对文件路径,如 css / target.css ../ css / target.css

解决方案

/ div>

CSS中的内部样式通常比外部样式具有更高的优先级。



因此,这(来自您的GitHub代码):

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

将始终执行,而不是这样:

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

因为它们都是同一个元素的样式,从最高优先级到最低优先级的完整顺序是:


  1. 内联样式(最高优先级)

  2. 内部样式

  3. 外部样式(最低优先级)


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?

解决方案

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)

这篇关于提交给insertCSS()的文件路径应该是相对的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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