css 伪类:悬停不起作用

发布于 2024-09-25 16:56:54 字数 323 浏览 0 评论 0原文

我正在努力让一个最简单的 css 悬停伪类发挥作用。有人知道为什么以下不起作用吗?

css

#hidden {display:none;}
#show:hover #hidden{display:block;}

html

<a href="#" id="show">show</a>
<div id="hidden">here i am</div>

我真的觉得问这么简单的问题很愚蠢,我这样做了一百次,但不明白为什么这不起作用。

I am struggling to get a simplest css hover pseudoclass to work. Anybody knows why the following doesnt work?

the css

#hidden {display:none;}
#show:hover #hidden{display:block;}

the html

<a href="#" id="show">show</a>
<div id="hidden">here i am</div>

I really feel stupid asking such a simple question, i did this a hunderd times, but cant figure out why this shouldnt work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-10-02 16:56:55

试试这个

#show:hover + #hidden{display:block;}

:hover #hidden 暗示 #hidden 是悬停元素的子元素。 + 选择器查找下一个相邻的同级。

Try this

#show:hover + #hidden{display:block;}

:hover #hidden implies that #hidden is a child of the hover element. The + selector looks for the next adjacent sibling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文