I have a number of nested elements, and I'm trying to select only the first N levels. The below shows a working example, where I'm selecting the first 7 levels and styling them. That works exactly how I want, however, I was hoping there was a simplified way of selecting these elements.
In my actual use case, I don't know the total number of nested elements, and I'm trying to select the first 50 levels, so using the above method would be quite messy. Unfortunately, I can't change the HTML in my application, so it needs to be a CSS only method. Thanks.
.container > div,
.container > div > div,
.container > div > div > div,
.container > div > div > div > div,
.container > div > div > div > div > div,
.container > div > div > div > div > div > div,
.container > div > div > div > div > div > div > div {
border-left: 1px solid;
padding-left: 15px;
}
<div class="container">
<div>
A
<div>
B
<div>
C
<div>
D
<div>
E
<div>
F
<div>
G
<div>
H
<div>
I
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>