我想僅爲以下DOM的第一個div添加邊框。但邊界適用於所有的divs。在嵌套的DOM結構中隱藏一個具有特定類的div
<li class="x-tree-node">
<div ext:tree-node-id="xnode-6" class="x-tree-node-el x-unselectable x-tree-node-expanded" unselectable="on">
</div>
<ul class="x-tree-node-ct">
<li class="x-tree-node">
<div ext:tree-node-id="xnode-17" class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon gx-tree-layer-icon" unselectable="on">
<input class="x-tree-node-cb" type="checkbox" checked="">
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div ext:tree-node-id="xnode-16" class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon gx-tree-layer-icon" unselectable="on">
<input class="x-tree-node-cb" type="checkbox" checked="">
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div ext:tree-node-id="xnode-15" class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon gx-tree-layer-icon" unselectable="on">
<input class="x-tree-node-cb" type="checkbox" checked="">
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div ext:tree-node-id="xnode-14" class="x-tree-node-el x-tree-node-leaf x-unselectable" unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon gx-tree-layer-icon" unselectable="on">
<input class="x-tree-node-cb" type="checkbox" checked="">
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
<li class="x-tree-node">
<div ext:tree-node-id="xnode-13" class="x-tree-node-el x-tree-node-leaf x-unselectable " unselectable="on"><span class="x-tree-node-indent"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-icon"></span><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-ec-icon x-tree-elbow-end"><img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" class="x-tree-node-icon gx-tree-layer-icon" unselectable="on">
<input class="x-tree-node-cb" type="checkbox" checked="">
</div>
<ul class="x-tree-node-ct" style="display:none;"></ul>
</li>
</ul>
</li>
我嘗試了以下方法。這些都不適合我。
.x-tree-node-el:nth-child(1){
border: 1px solid red;
}
/*
.x-tree-node-el ~ .x-tree-node-el {
border: none;
}*/
/*
#layerTree > .x-tree-node div:first-of-type {
display: none;
}*/
/*
#layerTree li.x-tree-node > div{
display: none;
}
#layerTree li.x-tree-node > div ~ div {
display: block;
}*/
/*.x-tree-node-el:first-of-type{ display:none; }*/
它必須是一個CSS唯一的解決方案。任何幫助?
您的列表中的元素在裏面你需要這個類 「X-樹節點-EL」 在每一個DIV? – avilac
是的,我需要它在每一個div。不幸的是,我不能改變DOM結構和屬性,類。 –
爲什麼不移除所有嵌套元素的邊界'.x-tree-node-el .x-tree-node-el {border:none}'; –