[英]css hover element to show child, how can I keep the hover css on the parent when I mouseover the child?
I have a <ul>
with several <li>
elements. 我有一个带有几个<li>
元素的<ul>
。 Inside the <li>
element there is a large <div>
that is hidden by default. 在<li>
元素内部有一个默认隐藏的大<div>
。 When I hover the <li>
its background changes color as does the bottom border as well as displaying the <div>
. 当我悬停<li>
它的背景会像底部边框一样改变颜色,也会显示<div>
。 This is the expected behavior. 这是预期的行为。 Note I am using css and not javascript for the hover effect. 注意我使用css而不是javascript来悬停效果。 .menuItem:hover .menuBody { display:block;}
. .menuItem:hover .menuBody { display:block;}
。 My problem is that when I hover over the now showing <div>
its parent, the <li>
in this case, loses it's hover style. 我的问题是,当我将鼠标悬停在现在显示的<div>
其父级时,在这种情况下<li>
会丢失它的悬停样式。 How can I force the parent to keep the hover styling when I hover over the <div>
? 当我将鼠标悬停在<div>
时,如何强制父母保留悬停样式? Basic html for the menu is like this. 菜单的基本html是这样的。 Any help or tips is of course appreciated. 任何帮助或提示当然是值得赞赏的。
<ul>
<li class="menuItem">
<a href="#">MenuItem</a>
<div class="menuBody></div>
</li>
</ul>
What you are asking is actually default behavior. 你问的实际上是默认行为。 When you hover over a child, the parent also receives the hover status, and the hover css should still be displayed. 当您将鼠标悬停在子项上时,父项也会收到悬停状态,并且仍应显示悬停css。 Have a look at this example: 看看这个例子:
http://jsfiddle.net/jxZ6S/ http://jsfiddle.net/jxZ6S/
We will need some more code to see what exactly is wrong. 我们需要更多代码来查看究竟是什么问题。 Are you sure you are applying the hover style to the parent, and not to the a
? 您确定要将悬停样式应用于父级,而不是a
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.