我该如何修复它,我需要在带有 div 的复选框中使用(两个部分都没有 div 它可以工作),我只能使用纯 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.
您必须将 html 结构更改为:
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>
引用
关于html - CSS 选择器,div 输入 :checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26573896/