html - CSS 选择器,div 输入 :checked

标签 html css

我该如何修复它,我需要在带有 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>

引用

General sibling selectors

关于html - CSS 选择器,div 输入 :checked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26573896/

相关文章:

html - 选择css中元素的所有第n次出现

html - 在图像中插入字段

html - 我可以向纯 css slider 添加点吗?

html - 可折叠的 div - 展开和折叠

html - 将三个 div 居中并排放置

javascript - 具有相同 id 的 jQuery .before

php - 创建一种从 JSON 日期时间搜索日期范围的方法

javascript - 下拉菜单 : Infinite Slide on Hover with jQuery

javascript - 链接到 anchor 并打开 Accordion

html - 如何在容器中垂直居中行?