CSS problem - an element only works if its has no parent (using jquery) -
i have code:
css:
.taglist { float:left; margin-left:30px; } .taglist ul { overflow:auto; list-style-type:none; border:1px solid #999; background:#ccc; padding:20px; min-height:150px; max-height:150px; width:100px; } .taglist li { display:block; border:1px solid #999; background:#fff; width:80px; padding:5px 10px; margin-bottom:5px; } .tag_selected { background:#ffc; }
html:
<div class="taglist"> <ul id="list1"> <li id="1">1</li> </ul> </div>
now i'm using jquery one.. when item on list selected, should change class tag_selected.
problem is, works if remove ".taglist " before ul , li css, , don't want because want style on "taglist" div..
i'v tried every combination ".taglist tag_selected", ".taglist ul li tg_selected", etc. nothing works !!
what can do?
btw, trying line:
<li class="tag_selected" id="1">1</li>
gave same result, no change ever..
thanks in advance!
your problem seems css selector specificity.
the rules .taglist ul
, .taglist li
more specific .tag_selected
, therefore class assigned background overridden .taglist li
.
this should work
.taglist li.tag_selected { background:#ffc; }
the specificity order (weakest strongest) tag, class, id. easiest way remember calculated treat sum of each digit, tag 1s, class 10s, , id 100s.
li
- 1.taglist
- 10.taglist li
- 11li#myid
- 101div.taglist li.tag_selected
- 22
see http://htmldog.com/guides/cssadvanced/specificity/ or google "css specificity".
Comments
Post a Comment