<分区>
<分区>
<style>
div{
width: 300px;
height: 300px;
background-color: blue;
display: none;
}
.hei:hover+div{
display: block;
}
</style>
<p class="hei">slm</p>
<br>
<p class="hei">hei</p>
<div class=""></div>
我给了他们相同的类,但只有 p 元素有效。我检查了 w3 学校,但找不到任何东西。
最佳答案
这是因为 +
选择器仅针对下一个元素,而 ~
在您的情况下针对所有下一个 div 的
。所以你的 CSS 将类似于这样的东西:.hei:hover~div
。
在这里您可以找到有关此行为的更多信息。 Difference between the selectors div + p (plus) and div ~ p (tilde)
ul ~ p {
color: red;
}
This sibling combinator is similar to X + Y, however, it's less strict. While an adjacent selector (ul + p) will only select the first element that is immediately preceded by the former selector, this one is more generalized. It will select, referring to our example above, any p elements, as long as they follow a ul.
第二个提示:不要使用 https://www.w3schools.com/对于学习,它的例子很差,并没有真正涵盖所有信息。 而是去寻找 https://developer.mozilla.org/en-US/
关于html - 为什么我不能将鼠标悬停在另一个 p 元素上并得到相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58309909/