我想更改“控制组”中每个按钮的背景颜色。我知道如何在不按下按钮的情况下更改背景颜色:(第一部分CSS起作用了!)

.ui-page-theme-a .ui-btn.ui-btn{
    background-color: #123456;
}


但是,如果按钮处于活动状态,则以下代码无法更改颜色:

.ui-page-theme-a .ui-btn.ui-btn-active{
    background-color: #123456;
}


这是我完整的html代码:

<html>

<head>
    <meta name=viewport content="user-scalable=no,width=device-width" />
    <link href="css/colorpicker.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
    <script src="js/colorpicker.js"></script>
    <script>
        onStart();
    </script>
</head>

<body>
    <div class="container">
        <div id="preview" class="preview"></div>
        <p id="output"></p>

        <fieldset data-role="controlgroup" data-type="horizontal">
            <legend>Horizontal controlgroup, checkbox:</legend>
            <input type="checkbox" id="modul1">
            <label for="modul1">Modul 1</label>
            <input type="checkbox" id="modul2">
            <label for="modul2">Modul 2</label>
            <input type="checkbox" id="modul3">
            <label for="modul3">Modul 3</label>
            <input type="checkbox" id="modul4">
            <label for="modul4">Modul 4</label>
            <input type="checkbox" id="modul5">
            <label for="modul5">Modul 5</label>
            <input type="checkbox" id="modul6">
            <label for="modul6">Modul 6</label>
            <input type="checkbox" id="modul7">
            <label for="modul7">Modul 7</label>
            <input type="checkbox" id="modul8">
            <label for="modul8">Modul 8</label>
        </fieldset>

        <div class="colorpicker" style="display:none">
            <canvas id="picker" var="2" width="300" height="300"></canvas>
        </div>
    </div>
</body>

</html>


这是为您提供的实时代码:http://jsfiddle.net/DCtEF/

最佳答案

迅雷,您的修复非常简单,有两种方法可以解决此问题,一种(第二种选择)可能更可取。

真正的问题是链接优先级。此样式表:"http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css"是覆盖您的样式的内容。可能您的头部链接了自己的样式表,然后是其下面的样式表。



快速简便的方法是在CSS属性的末尾简单地添加!important
http://jsfiddle.net/SaDrZ/

background-color: orange !important;


这可能有点讨厌,通常最好的做法是在可能的情况下避免使用!important。



更为可取的方法是,只需确保您在自己的样式表之前已链接上述样式表。像下面...

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

10-05 20:57
查看更多