Hover works in one case but not in another

css hover
mouseover and mouseout in javascript examples
mouseenter vs mouseover
mouseleave
simulate hover on touch devices
css selectors
hover not working
mobile hover alternative

The following HTML and CSS code snippet works fine:

.dropdown:hover .features-menu{
  display: flex;
  flex-direction: column;
  background: #B2D6FF;
  border-radius: 5px;
  padding-top: 60px;

  position: absolute;
  top: 50px;
  left: 50px;

}
<li class='dropdown'>Features ▾
  <ul class='features-menu'>
    <li><a href='#'>Harder</a></li>
    <li><a href='#'>Better</a></li>
    <li><a href='#'>Faster</a></li>
    <li><a href='#'>Stronger</a></li>
  </ul>
</li>

To answer your question you need to understand CSS selectors more.

Lets explain the first (working CSS) selector .dropdown:hover .features-menu = Select all elements with class dropdown when they are in hover state and set up properties for features-menu class inside that .dropdown

Now the second CSS .dropdown span:hover .features-menu reads: Select all span elements within class dropdown when they are in hover state and set up properties for features-menu class inside that .dropdown span

Since in your working example .dropdown element includes .features-menu it's OK. But in second case .dropdown span element doesn't include .features-menu

Using "sibling" selector might help here:

.dropdown span:hover ~ .features-menu {
  display: flex;
  flex-direction: column;
  background: #B2D6FF;
  border-radius: 5px;
  padding-top: 60px;

  position: absolute;
  top: 50px;
  left: 50px
}
<li class='dropdown'><span>Features ▾</span>
  <ul class='features-menu'>
    <li><a href='#'>Harder</a></li>
    <li><a href='#'>Better</a></li>
    <li><a href='#'>Faster</a></li>
    <li><a href='#'>Stronger</a></li>
  </ul>
</li>

Moving the mouse: mouseover/out, mouseenter/leave, The mouseover event occurs when a mouse pointer comes over an element, and That's normal and just means that the mouse came not from another element, In case of fast mouse movements, intermediate elements may be Your solution doesnt work because is not accounting for nested elements. One side of hoverboard not working is a common problem. In most cases, the reason for this is a faulty gyroscope. This problem can be solved by replacing the gyroscope.

Assuming that this is how your markup looks like:

<li class='dropdown'><span>Features ▾</span>
  <ul class='features-menu'>           
  <li><a href='#'>Harder</a></li>
  <li><a href='#'>Better</a></li>
  <li><a href='#'>Faster</a></li>
  <li><a href='#'>Stronger</a></li>
  </ul> 
</li>  

A:hover not working, but working ??? > Litmus, Hello all, I have an email with two different :hover colors. One is working, and the other is not. Yet, it's the same code. I opted to not use a:hover  That’s when I noticed a slight difference between my test cases and the real world use case. Double tap! The culprit, as it turns out, is a combination of two factors. It’s not simply a :hover rule that triggers the double tap behavior. It’s a :hover Rule that either hides or shows another element using visibility or display. For example:

Your original CSS should work with the new <span> introduced. The CSS selector for the hover, .dropdown:hover .features-menu will still target the <span>'s parent element, meaning that the hover effect should still work as the parent element still exists.

I've put this on a codepen to demonstrate: https://codepen.io/littlefinger42/pen/ebWYJP

Finally, a CSS only solution to :hover on touchscreens, There have been problems with the :hover pseudo-class ever since the first web has a package ready and armed for just this problem, but that is not the case. Maybe one works well on a special device, but not the other. This CSS declaration: .dropdown span:hover .features-menu will only apply to .features-menu which is a child element of span. However on this case, .features-menu is a sibling of span and that's why it's not working. You can try using the adjacent sibling selector (+) instead:

Selectors, For example, in HTML, element names are case-insensitive, but in XML they are The link pseudo-classes. E:active. E:hover. E:focus, Matches E during certain want selectors to match an element that is the descendant of another element in the they work even if the default values are not included in the document tree. When yours finally kicks the bucket, all you need to do is purchase a new one and replace it. Make sure to pick up the battery that works with your model, or a UL2271. The ULs are made by Samsung and considered the safest on the market. Replacing Gyroscopes. This one is a tricky fix.

Metadata On Hover, Trigger: Popup content does not obscure any part of its triggering content. Popup content that appears only on focus or mouse hover can present many challenges for Tooltips are an issue, but then they don't work in other cases either. but this only works, because these elements are childs in the same hierarchy. For elements, that are inside another, you can use:.element:hover .another_element { } Of course you can use javascript for this, but that would be seriously overloaded for a simple animation. Depends of course, on what kind of animation you are trying to achieve.

Sass: @extend, There are often cases when designing a page when one class should have all When one class selector extends another, it works exactly as though you .error:​hover { background-color: #fee; } .error--serious { @extend .error; border-width: 3px; } so that they work no matter which order the HTML elements are nested. I put a hover effect on the nav menu on my site and it works in Chrome & FF but not in IE. Just in case it makes a difference, I also have a CSS animation effect on another element, plus a jQuery animation effect which is on the same element as the CSS one, but it's a different element to the one the hover effect is on.

Comments
  • Great answer! Thank you!