得到那些有子孩子ul的li [英] Get those li that have sub children ul
本文介绍了得到那些有子孩子ul的li的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取有子级ul
的那些li
.我想将CSS设置为那些li
.我不能设置类,因为li
是动态打印的.当我如下设置CSS时,它将所有父li
都设置为plus.
How to get those li
that have children ul
. I want to set CSS to those li
. I can't set class because li
are dynamically print. When I set CSS as below so it set all parent li
to plus.
.ul{
width:200px;
position:relative;
}
.ul li{
position:relative;
}
.ul > li:before{
content : '+';
position: absolute;
top: 0;
right: 7px;
}
<ul class="ul">
<li>List 1</li>
<li>List 2</li>
<li>List 3
<ul>
<li>Sub List 1</li>
<li>Sub List 2</li>
<li>Sub List 3</li>
</ul>
</li>
<li>List item 4</li>
</ul>
This is style for that.
推荐答案
您实际上非常亲密.诀窍是简单地设置.ul
内部的每个ul
的样式.然后将+
移动到您希望其显示的位置(即,在父li的第一行之后).
You're very close actually. The trick is to style simply each ul
that is inside a .ul
. Then move the +
to where you want it to appear (i.e. after the first line of the parent li).
.ul {
width: 200px;
position: relative;
}
.ul li {
position: relative;
}
.ul ul::before {
content: '+';
position: absolute;
top: 0;
right: 7px;
}
<ul class="ul">
<li>List 1</li>
<li>List 2</li>
<li>List 3
<ul>
<li>Sub List 1</li>
<li>Sub List 2</li>
<li>Sub List 3</li>
</ul>
</li>
<li>List item 4</li>
</ul>
This is style for that.
这篇关于得到那些有子孩子ul的li的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文