鼠标悬停<li id="cloud">时无法显示<ul id="cloudmenu">的问题求助
Hey there! Let's break down why your CSS selector isn't working and get that menu showing up on hover.
The Root Problem
Your current selector #cloud:hover #cloudmenu is a descendant selector — it only targets elements with the ID cloudmenu that are nested inside the #cloud <li>. But based on your description, #cloudmenu is on the next line (HTML line 51) right after #cloud (line 50), which means they're sibling elements (share the same parent), not parent-child. That's why the selector can't find it.
The Fixes
Depending on your exact HTML structure, use one of these sibling selectors:
Adjacent Sibling Selector (
+)
Use this if#cloudmenuis immediately right after#cloudwith no other elements in between:#cloudmenu { display: none; } #cloud:hover + #cloudmenu { display: grid; }General Sibling Selector (
~)
Use this if there are other elements between#cloudand#cloudmenu:#cloudmenu { display: none; } #cloud:hover ~ #cloudmenu { display: grid; }
Quick Check to Confirm
Double-check your HTML structure to make sure:
#cloudand#cloudmenushare the same direct parent element#cloudmenuisn't accidentally nested inside another element (like a different<li>or<div>)
If your structure is more complex (e.g., the menu is nested elsewhere), you might need to adjust your selector hierarchy or use a small JavaScript snippet, but the sibling selectors should cover most cases matching your description.
内容的提问来源于stack exchange,提问作者veryslothysloth

