Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML / CSS mouse context menu
    text
    copied!<p>I know I will be hissed at for asking a question like this, but I'm new to selectors and am struggling with hover effects for a child UL embedded in an existing UL.</p> <p>The HTML:</p> <pre><code> &lt;ul id="ctxMenuStock"&gt; &lt;li&gt;&lt;a href="#ctxCMDCopy"&gt;Copy&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#ctxCMDReserve"&gt;Reserve/Outgoing&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Set Status &lt;span style="font-family: Webdings"&gt;6&lt;/span&gt;&lt;/a&gt; &lt;ul id="ctxMenuStockStatuses" runat="server"&gt;&lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>ctxMenuStockStatuses is populated by server code on page load.</p> <p>The CSS:</p> <pre><code> #ctxMenuStock, #ctxMenuStock ul, #ctxMenuPending, #ctxMenuPending ul{ display:none; margin:0; padding:0; list-style-type:none; list-style-position:outside; position:fixed; line-height:1.5em; } #ctxMenuStock a:link, #ctxMenuStock hr, #ctxMenuStock a:active, #ctxMenuStock a:visited, #ctxMenuPending a:link, #ctxMenuPending hr, #ctxMenuPending a:active, #ctxMenuPending a:visited{ display:block; padding:0px 5px; color:#fff; text-decoration:none; background-color:#333; } #ctxMenuStock&gt;li:hover ul, #ctxMenuStock&gt;li:hover ul li, #ctxMenuStock&gt;li:hover ul li a { color:#fff; background-color:#333; } #ctxMenuStock&gt;li:hover a, #ctxMenuPending&gt;li:hover a{ background-color:#fff; color:#333; } #ctxMenuStock ul li ul li a:hover, #ctxMenuPending ul li ul li a:hover{ background-color:#fff; color:#333; } #ctxMenuStockStatuses li { color:#fff; background-color:#333; } #ctxMenuStockStatuses li:hover { background-color:#fff; color:#333; } #ctxMenuStock li, #ctxMenuPending li{ float:none; position:relative; } #ctxMenuStock ul, #ctxMenuPending ul { position:absolute; display:none; float:left; } #ctxMenuStock li ul a, #ctxMenuPending li ul a { width:12em; margin: 0 0 0 4px; float:left; } #ctxMenuStock ul ul, #ctxMenuPending ul ul{ top:auto; } #ctxMenuStock li ul ul, #ctxMenuPending li ul ul { left:12em; margin:0px 0 0 10px; } #ctxMenuStock li:hover ul ul, #ctxMenuStock li:hover ul ul ul, #ctxMenuStock li:hover ul ul ul ul{ display:none; } #ctxMenuStock li:hover ul, #ctxMenuStock li li:hover ul, #ctxMenuStock li li li:hover ul, #ctxMenuStock li li li li:hover ul{ display:block; } #ctxMenuPending li:hover ul ul, #ctxMenuPending li:hover ul ul ul, #ctxMenuPending li:hover ul ul ul ul{ display:none; } #ctxMenuPending li:hover ul, #ctxMenuPending li li:hover ul, #ctxMenuPending li li li:hover ul, #ctxMenuPending li li li li:hover ul{ display:block; } </code></pre> <p>The menu is basically styled as a dark background with white text, but on hover this reverses. This works ok for the parent menu, but the child menu doesn't change and remains white on black.</p> <p>I know some of this CSS is contradicting each other, but its becoming difficult to follow. I can't seem to find alot (if any) of working examples online of how to do this with sub-menus.</p> <p>Can somebody please show me the best approach for this.</p> <p><strong>EDIT:</strong> As requested, JSFiddle example created: <a href="http://jsfiddle.net/KzhEP/" rel="nofollow">http://jsfiddle.net/KzhEP/</a> Although in my main project, the oncontextmenu attribute is attached to each row of my table server-side. I have mocked up a simple example, but for some reason i cannot get the right click functionality working on jsfiddle.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload