已经很久了,但没有人明白这一点,所以我给你两分钱。
<style>
.popup { position: fixed; display: block; visibility: hidden; /* other styles */ }
#anchorid:target+.popup { visibility: visible; }
</style>
然后
<a href="#anchorid">Click to see the popup corresponding to the id</a>
<a name="anchorid" id="anchorid" class="clicked"></a>
<div class="popup">
The contents of this popup is hidden until the link above is clicked.
</div>
<a name="anchorid2" id="anchorid2" class="clicked"></a>
<div class="popup">
The contents of this popup is also hidden, and remains hidden until the anchor immediately preceding it becomes actively targeted.
</div>
现在会发生什么:当用户单击第一个链接时,href 仅包含一个锚点,因此它只是附加到地址栏中的 URL,而无需重新加载页面。带有 id 的锚#anchorid
现在被认为是 CSS 的目标。将它与+.popup
意味着“当该 id 也是当前目标锚时,选择紧跟在具有此 id 的元素之后的任何元素”。'+' 是强制性的,因为 achor 元素被认为只包含流元素,而 div 不是。