由其他元素强制悬停CSS3
嘿,我想做一个纯 CSS3 下拉导航。如果您将鼠标悬停在第一个项目上,它会更改背景并打开下拉子元素。这没关系。但是,如果我将鼠标悬停在下拉元素上,则更改后的背景将重置,就像未悬停一样。
如何更改由另一个元素悬停强制的元素的样式?
Hey I wanna do a pure CSS3 dropdown navigation. If you hover the first item it changes the background and opens the dropdown child element. This is okay. But if I hover the dropdown element the changed background resets like its not hovered.
How can I change the style of an element forced by the hover of an other element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确实想坚持使用纯 CSS3,您可以将两个对象放入一个容器中并在该容器中定义颜色。如有必要,请在下拉子项中覆盖它。
If you really want to stick to pure CSS3 you could put both objects into a container and define the color in this container. Overwrite it in the dropdown child if necessary.
这是一个仅 CSS 的快速下拉列表。保留背景的技巧是将悬停样式设置为主菜单项,而不是子菜单项。像悬停这样的事件,像 JS 一样,会冒泡。悬停子项也意味着悬停父项。
here's a quick CSS only dropdown. the trick to preserve the background is to set the hover style to the main menu item, and not to the submenu item. events like hover, like JS, bubble up. hovering a child will also mean hovering the parent.