1

I have a list like so:

    <ul id="main">
        <li>January
            <ul>
                <li>test</li>
                <li>test2</li>
            </ul>
        </li>

        <li>February
            <ul>
                <li>test</li>
                <li>test2</li>
            </ul>
        </li>
    </ul>

I would like to affect only the first level of li's - I thought this css would do the trick, but it appears to be not working correctly.

#main > li {
cursor: pointer;
list-style-image: url('plus_sign.gif');
}

The child lists still have a plus symbol next to them ... what would I be doing wrong?

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
joshft91
  • 1,755
  • 7
  • 38
  • 53

4 Answers4

1

This should work:

  #main  li {
    list-style-image: none;
  }    
  #main > li {
    cursor: pointer;
    list-style-image: url('plus_sign.gif');
  }    

list-style-image is an inheritable property so it takes the value from its parent.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
c-smile
  • 26,734
  • 7
  • 59
  • 86
1

You can try this css, it looks like what you want.

#main{
    cursor:pointer;
    list-style-image:url('http://www.w3schools.com/cssref/sqpurple.gif');
}
#main ul{
    /*If you don't want the hallow circles*/
    list-style:none;
    /*if you want the hollow cirles, remove list-style and uncomment list-style-image:none
     list-style-image:none;
    */
}

It will display the plus_sign.gif(sqpurple.gif in this case) only on January and February. See Fiddle

Fee
  • 243
  • 1
  • 9
  • Thanks for the answer. I'm starting to wonder if there's something going on that in my environment because I've typed character for character and still nothing. Frustrating. – joshft91 Nov 19 '12 at 03:47
  • Maybe you should try it in a new file, just these rules alone or even something simpler to try and find the source of your problem. Hope it works out for you in the end. – Fee Nov 19 '12 at 03:53
0

add another rule to deal with all other cases of li's:

ul > li{
    color: red;
    /*specifically*/
    list-style-image: none;
}

Give the css a default so your specific case will be an exception.

hyleaus
  • 755
  • 1
  • 8
  • 21
0

Create another style and modify the ul to utilize the class:

.main > li {
cursor: pointer;
list-style-image: url('imageurl');
}
.main > li > ul > li {
cursor: auto;
list-style-image: none;
}

<ul class="main">
    <li>January
        <ul>
            <li> test</li>
            <li>test2</li>
        </ul>
    </li>

    <li>February
        <ul>
            <li>test</li>
            <li>test2</li>
        </ul>
    </li>
</ul>
Kevin Wasie
  • 45
  • 1
  • 8