我有一个标准的嵌套 JQuery UI Accordion。我的问题是我想对内部手风琴进行与父手风琴不同的风格。我知道哪些 CSS 规则将样式应用于手风琴,但我找不到针对内部手风琴的选择器。
唯一接近的选择器是 :nth-child() 伪选择器。问题是我不知道内部手风琴有多少元素,也不知道顶部手风琴有多少元素。
一条规则是我知道永远不会有第三层嵌套。
此 CSS 规则设置所有手风琴标题的样式
.ui-accordion-header.ui-state-default {
background: none repeat scroll 0 0 #19A053;
border-color: #19A053;
}
我现在需要一种方法来做这样的事情
.ui-accordion-header.ui-state-default if-inside-another-accordion{
background: none repeat scroll 0 0 #dddddd;
border-color: #dddddd;
}
如果您是 CSS 选择器方面的专家,但从未见过 JQuery 生成的 HTML,这里是一个嵌套手风琴生成代码的示例。
<div id="content">
<div role="tablist" style="display: block;" class="gw_accordion ui-accordion ui-widget ui-helper-reset">
<div tabindex="0" aria-selected="true" aria-controls="ui-accordion-1-panel-0" id="ui-accordion-1-header-0" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-accordion-header-active ui-state-active ui-corner-top"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-s"></span><a class="gw_chapter_menu_link" href="#24" alt="">Top Level Header 1</a></div>
<div aria-hidden="false" aria-expanded="true" role="tabpanel" aria-labelledby="ui-accordion-1-header-0" id="ui-accordion-1-panel-0" style="display: block;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active">
<p>some text here</p>
<div role="tablist" style="display: block;" class="gw_accordion ui-accordion ui-widget ui-helper-reset">
<div tabindex="0" aria-selected="false" aria-controls="ui-accordion-2-panel-0" id="ui-accordion-2-header-0" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a class="gw_chapter_menu_link" href="#27" alt="Maybe Now???">Nested Header 1</a></div>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-2-header-0" id="ui-accordion-2-panel-0" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<p>some text here</p>
</div>
<div tabindex="-1" aria-selected="false" aria-controls="ui-accordion-2-panel-1" id="ui-accordion-2-header-1" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a class="gw_chapter_menu_link" href="#25" alt="">Nested Header 2</a></div>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-2-header-1" id="ui-accordion-2-panel-1" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<p>some text here</p>
</div>
</div>
</div>
<div tabindex="-1" aria-selected="false" aria-controls="ui-accordion-1-panel-1" id="ui-accordion-1-header-1" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a class="gw_chapter_menu_link" href="#26" alt="I hope this works">Top Level Header 2</a></div>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-1-header-1" id="ui-accordion-1-panel-1" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<p>some text here</p>
<div role="tablist" style="display: block;" class="gw_accordion ui-accordion ui-widget ui-helper-reset">
<div tabindex="0" aria-selected="false" aria-controls="ui-accordion-3-panel-0" id="ui-accordion-3-header-0" role="tab" class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a class="gw_chapter_menu_link" href="#28" alt="Really">Nested Header 1(for second top header)</a></div>
<div aria-hidden="true" aria-expanded="false" role="tabpanel" aria-labelledby="ui-accordion-3-header-0" id="ui-accordion-3-panel-0" style="display: none;" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom">
<p>some text here</p>
</div>
</div>
</div>
</div>
</div>