Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - target only one layer deep

I'm working with Sharepoint at the moment and to say it's code structure/layout is a mess would be a huge understatement. It has a left navigation, and I want all items in there to be styled with a div around them (I'd target them individually, but Sharepoint has hundreds of widgets each with their own name class), for example:

<div id="leftNav">
    <div id="widget1">
        <div></div>
        <div></div>
    </div>
    <div id="widget2">
        <div></div>
        <div></div>
    </div>
</div>

I've tried #leftNav div { } but that targets the sub divs too (and the sub divs of those divs) - is there anyway to just target the 'widget' divs?

Thanks!

like image 813
Nick Avatar asked Mar 11 '12 14:03

Nick


2 Answers

Use the direct child combinator, >:

#leftNav > div {
    /* ... */
}
like image 60
Ry- Avatar answered Oct 03 '22 00:10

Ry-


You can use the child selector to target the direct child of the elements.

#leftNav > div
like image 41
Andres Ilich Avatar answered Oct 02 '22 23:10

Andres Ilich