【问题标题】:Change collapsible list header colour when expanded [closed]展开时更改可折叠列表标题颜色[关闭]
【发布时间】:2014-01-27 08:10:13
【问题描述】:

我正在使用 Jquery Mobile(1.4) 开发跨平台应用程序。

我希望能够在展开时更改可折叠列表标题的背景颜色,并在折叠时将其设置回来。

谁能告诉我如何更改“可折叠列表标题”的背景颜色。

如果我们能够通过纯 CSS 做到这一点会更好。

提前谢谢你。

【问题讨论】:

  • 发布您的标记以及您已经尝试过的内容
  • 我很确定当元素折叠或折叠时已经添加/删除了适当的类 - 所以去看看 DOM 检查器,找出这些类是什么,然后简单地使用它们在两种状态下形成不同的元素。
  • CBroe,我确实尝试过,但看不到我在以下课程中所做的更改:- ui-collapsible-heading ui-collapsible-heading-collapsed.ui-collapsible-collapsed + .ui-collapsible:not(.ui-collapsible-inset) > .ui-collapsible-heading .ui-btn。我希望列表折叠时更改列表标题的背景颜色

标签: css jquery-mobile jquery-mobile-collapsible


【解决方案1】:

随心所欲地改变颜色

.ui-collapsible-heading-collapsed > .ui-collapsible-heading-toggle{
    background:red;
}

.ui-collapsible-heading-toggle{
    background:yellow;
}

DEMO

【讨论】:

  • 谢谢卡维内什。不过我不想和桌子有任何关系。但是,是的,“可折叠列表标题”变为黄色,这就是我想要简单地使用 CSS 做的事情。因为在我的应用程序中会有多个可折叠列表,我不想使用 javascript 函数来处理颜色变化。我尝试在 JQM 1.4 CSS 中对 ui-collapsible-heading ui-collapsible-heading-collapsed.ui-collapsible-collapsed + .ui-collapsible:not(.ui-collapsible-inset) > .ui-collapsible-heading .ui-btn 这些类中的 CSS 进行更改,但我无法让它工作
  • @BetRob 你在你的折叠集中使用图标吗?
  • 是的,展开和折叠的图标。
  • @BetRob 现在是 k 如果是这样检查回答。
  • 太棒了,谢谢!!!
【解决方案2】:

HTML

 <div data-role="collapsible" id="clp" class="width70" data-mini="true">
 <h3 style="width: 120px">
                    Search
                </h3>

<div>
    <table data-role='table' id='tblSearch' data-mode='reflow' class='my-custom-breakpoint'>
        <thead id="tbl1">
            <tr>
                <th>HEADER1</th>
                <th>HEADER2</th>
                <th>HEADER3</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <input type="text" id="txtInsuredName" name="txtInsuredName" />
                </td>
                <td>
                    <input type="text" id="txtPolicy" name="txtPolicy" />
                </td>
                <td>
                    <input type="text" id="txtOT" name="txtOT" maxlength="10" />
                </td>
            </tr>
        </tbody>
    </table>
</div>

JQUERY

  $('#clp').bind('expand', function () {
  $('#tbl1').addClass('greybackcolor');
  }).bind('collapse', function () {
  $('#tbl1').removeClass('greybackcolor');
 });

CSS

.width70 {
 width: 85%;
}
.greybackcolor {
 background: yellow;
}
@media (min-width: 400px) {
 /* Show the table header rows and set all cells to display: table-cell */
   .my-custom-breakpoint td, .my-custom-breakpoint th, .my-custom-breakpoint tbody th,     .my-custom-breakpoint tbody td, .my-custom-breakpoint thead td, .my-custom-breakpoint thead th {
    display: table-cell;
    margin: 0;
 }
 /* Hide the labels in each cell */
 .my-custom-breakpoint td .ui-table-cell-label, .my-custom-breakpoint th .ui-table-cell-label {
    display: none;
  }
}

请找到工作演示:DEMO

【讨论】:

  • 谢谢罗希特!!但是,我想要实现的是,当这个列表展开时,我想改变标题的背景颜色来改变,当折叠时它应该恢复。
  • 已更新我的演示链接,如果您需要更多帮助,请查看并告诉我
  • Rohit by headers 我的意思是可折叠列表标题,我们希望当列表中的“+”符号变为“-”时,可折叠列表的背景也会发生变化。谢谢
猜你喜欢
  • 2015-06-20
  • 2021-11-23
  • 1970-01-01
  • 2011-10-03
  • 1970-01-01
  • 1970-01-01
  • 2020-01-30
  • 1970-01-01
  • 2018-06-14
相关资源
最近更新 更多