简体   繁体   中英

CSS Selector, div input:checked

How could I repair it, I needed in checkbox with the div (without div in both parts it works), I can use only pure CSS.

Html:

<div><input type="checkbox"></div>
<ul>
    <li>PSD WEBSITES</li>
    <li>UI KITS</li>
    <li>PREMIUM PSD</li>
    <li>ABOUT</li>
    <li>BLOG</li>
</ul>

CSS:

div input:checked ~ ul {
    display: none;
}

The ~ combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.

You have to change your html structure to:

 div input:checked ~ ul { display: none; } 
 <div> <input type="checkbox" /> <ul> <li>PSD WEBSITES</li> <li>UI KITS</li> <li>PREMIUM PSD</li> <li>ABOUT</li> <li>BLOG</li> </ul> </div> 

Reference

General sibling selectors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM