简体   繁体   English

为什么 CSS 悬停不起作用?

[英]Why is the CSS hover not working?

My site is test06.menchasha.ru.我的网站是 test06.menchasha.ru。 I am trying to apply a hover effect.我正在尝试应用悬停效果。 A div in the right should appear when the link, 'Promotional Activities' is hovered.当链接“促销活动”悬停时,右侧应该会出现一个 div。 Example例子

I used the following code:我使用了以下代码:

 .child1 { display: none; } a .title1:hover + .child1 { display: inline-block; }

But the hover effect is not working.但是悬停效果不起作用。 What should I correct?我应该纠正什么? Thank you in advance!先感谢您!

I've checked the code in your link - you simply can't achieve the effect you need with your structure and only with CSS.我已经检查了您链接中的代码 - 您根本无法通过结构实现所需的效果,而只能使用 CSS。

Here is your code:这是你的代码:

a .title1:hover + .child1 {
  display: inline-block;
}

If you want it to work the way you need your a element must have 2 children: .title1 and .child1 , also .child1 must be direct sibling of .title1 cause + selector helps you to access only the nearest sibling of the element.如果你想它的工作方式,你需要你的a元素必须有2个孩子: .title1.child1 ,也.child1必须是直接的兄弟.title1原因+选择可以帮助你只能访问元素的最近的兄弟。 But in your structure all the .child elements are not siblings of .title elements, they are in another div block.但是在您的结构中,所有.child元素都不是.title元素的兄弟元素,它们位于另一个div块中。 So just use JS to make them visible on hover.所以只需使用 JS 使它们在悬停时可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM