CSS select all li which not contains a tag

前提是你 提交于 2020-01-02 20:08:53

问题


I want to select all li which not contains a tag in css:

ul.sf-menu li:not(a)

But looks like it is not working.

Need help

<ul class="sf-menu sf-js-enabled sf-shadow">
    <li>
        <a href="/ ">
    </li>
    <li> need to select this li because it is not contains a href
        A 
        <ul style="visibility: visible; display: block">
            <li>
                <a href="/B-1">
            </li>
            <li>
                <a href="/B-2">B-2</a>
            </li>
         </ul>
      </li>
 <li>


回答1:


Two things

1) Your selector doesn't match the question you're asking. It currently selects every LI that is not an Anchor. This should be every LI on the page.

2) What you want can't be done with CSS right now. Your best bet would be to use some JavaScript to do this. For instance, the following jQuery would work.

$("ul.sf-menu li:not(:has(a))").doSomething()


来源:https://stackoverflow.com/questions/7467590/css-select-all-li-which-not-contains-a-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!