如果使用ID和类,CSS Tilda不起作用
#header__menu~.header__button {
background-color: red;
}
<div class="header__menu">
<div class="header__button">
<div class="header__button-1 header__line"></div>
<div class="header__button-2 header__line"></div>
<div class="header__button-3 header__line"></div>
</div>
<input type="checkbox" name="" id="header__menu">
</div>
#header__menu~.header__button {
background-color: red;
}
<div class="header__menu">
<div class="header__button">
<div class="header__button-1 header__line"></div>
<div class="header__button-2 header__line"></div>
<div class="header__button-3 header__line"></div>
</div>
<input type="checkbox" name="" id="header__menu">
</div>
this code just doesn't work. I have no idea why. I spent like 30 minutes trying to fix it, but I have literally no idea why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
tilde是a
。但是,如果您做到了,
那将不会发生任何事情。没有标头__ button-2是在.header__ button-3之后进行的。
The tilde is a General Sibling Combinator which means it works on siblings, not parents and children. Specifically, it works on siblings B that comes after sibling A and has the same parent, where you have A ~ B. So, in your code, if you have
then .header__button-2 would have a red background. But if you did
there wouldn't be anything that really happens. There is no header__button-2 that comes after a .header__button-3.
相关选择器的行为类似于相邻的选择器,但与样式规则不同,附近的所有元素都适用。
Related selectors behave similar to neighboring selectors, but unlike the, style rules apply to all nearby elements.