我想仅为以下DOM的第一个div添加边框。但是边界适用于所有的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的解决方案。有什么帮助吗?
答案 0 :(得分:2)
您可以尝试:
.x-tree-node-ct li:first-child div:first-child {
border: 1px solid red;
}
答案 1 :(得分:2)
我假设显示的HTML未包含在与ul
相同的其他.x-tree-node-ct
中
.x-tree-node-el { border: 1px solid red; }
.x-tree-node-ct .x-tree-node-el { border: 0 }
这将删除.x-tree-node-ct
使用您的示例代码
工作Fiddle答案 2 :(得分:1)
尝试如下。
.x-tree-node-ct li.x-tree-node:first-child div.x-tree-node-el {
border: 1px solid green;
}
答案 3 :(得分:0)
试试这个
.x-tree-node-el:not(.x-tree-node-leaf){
border: 1px solid red;
}
.x-tree-node-el:not(.x-tree-node-leaf){
border: 1px solid red;
}
<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>