【问题标题】:How to change the background color of jquery mobile footer?如何更改jquery mobile页脚的背景颜色?
【发布时间】:2013-04-01 04:25:49
【问题描述】:

我正在使用 jquerymobile 为 iOS 构建一个 PhoneGap 应用程序,我尝试更改 jquerymobile 的背景,但我不能。 这是我的html源代码:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.css" />

        <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.2.1/jquery.mobile-1.2.1.min.js"></script>
        <script type="text/javascript" src="../../js/cordova-2.5.0.js"></script>
            <link rel="stylesheet" href="mainUI.css"/>


    </head>
    <body>

        <div data-role="page" id='mypage'>
            <div data-role="header" data-position="fixed">
                <h1>Page Title</h1>
                <a data-role="button" data-rel="back">back</a>
            </div><!-- /header -->

            <div data-role="content">
                content
            </div><!-- /content -->
            <div class="my-footer" style="background-color: #00FF00;" data-role="footer" data-position="fixed">
                <div class="my-tabbar">
                    MYTEST div
                </div>
            </div>
        </div><!-- /page -->
    </body>
</html>

这是我的自定义 CSS 文件:

.my-footer {
    background-color:   #ff0000;    
}
.my-footer .my-tabbar{
    background-color:   #ff0000;
}
.my-tabbar{
    background-color: #ff00ff;
}

当我在 Chrome 浏览器上运行这个 html 时,我工作了。但是当我在 iPhone5 设备上运行时,它没有。 请帮忙。

【问题讨论】:

  • 你试过!important 吗?
  • 是的,我试过了,但没有任何改变。 .my-footer .my-tabbar{ background-color: #ff0000 !important; }
  • 尝试覆盖整个背景。 background: #ff0000 !important; 找出问题所在。我认为这是一个 CSS 问题,而不是 phonegap 对页脚做些什么。
  • 尝试覆盖 .ui-bar-a 类
  • 我试过这个:'.my-footer .my-tabbar{ background:transparent url(../../res/img/menu_over.png) !important; } ' 但它仍然无法在 iPHone 上运行,它只能在桌面浏览器(如 chrome、safari)上运行

标签: jquery ios css cordova jquery-mobile


【解决方案1】:

您需要使用实际的 jQuery 页脚移动选择器。您可以在 iPhone 上使用 Safari 网络检查器来查找任何内容的确切选择器,并在您自己的样式表中进行相应更改。

以下是一些我认为可以胜任的选择器:

.ui-bar-a.ui-footer {

/*Change background here */

}

P.S 在你的样式表中,如果你想覆盖 jQuery mobile,让你的选择器更具体。 所以不是...

.ui-bar-a.ui-footer {

/*Change background here */

}

使用....

.my-footer.ui-bar-a.ui-footer {

/*Change background here */

}

或者....

.home-page .ui-bar-a.ui-footer {

/*Change background here */

}

【讨论】:

    【解决方案2】:

    感谢我的同事,我终于找到了根本原因。当我用 PC 浏览器测试这个 html 文件时,我双击它。所以它作为一个普通的html文件运行,它将加载&lt;header&gt;标签内所有声明的资源。但是当我在 iPhone 上测试时,我使用 $.mobile.changePage() 从另一个页面导航到这个 html 文件,这将仅加载 &lt;body&gt; 标记的内容。在这种情况下,我的css 文件没有加载。这就是我的页面无法在 iPhone 上运行的原因。

    所以,要解决这个问题,我只需将所有资源声明(在&lt;head&gt; 内)移动到&lt;body&gt; 标记的底部。这样,资源文件就会一直被加载。

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      何必手动编辑 CSS 并搞乱框架。 JQuery Mobile 提供了一个优雅的解决方案来更改 JQM 元素(例如页眉、页脚、按钮等)的颜色主题。

      你听说过Theme Roller吗?主题滚轮可让您将您选择的颜色导入您的 UI 元素。添加您的颜色并将 css 文件导入到项目中,并将 data-theme 元素更改为您在 Theme Roller 中使用的色板。

      我个人推荐您在 Swatch “g” 之后的自定义主题,并在 jQuery 移动 css 文件之前导入您的 css 文件。

      【讨论】:

      • Theme Roller 非常有限...例如,我尝试为列表分隔线设置主题,但我不能...还有更多示例...我认为这就是为什么这么多人们直接使用 css。
      猜你喜欢
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多