Note that there are some explanatory texts on larger screens.

plurals
  1. POOverlap list item with another child element
    text
    copied!<p>I have list of items. When hover, the background should highlight gray per item. I also want to be able to hover on "X" to change its background to red.</p> <p>However, in the code below, when I hover on each line, the item background lays on top of "X" and there is no way to hover on "X".</p> <p><strong>Code:</strong> <a href="http://jsfiddle.net/qhoc/7vtZT/2/" rel="nofollow">http://jsfiddle.net/qhoc/7vtZT/2/</a></p> <p><strong>HTML:</strong></p> <pre><code>&lt;ul&gt; &lt;li&gt; &lt;a&gt;Long title for Item 1&lt;/a&gt; &lt;i class=icon&gt;&lt;/i&gt; &lt;/li&gt; &lt;li&gt; &lt;a&gt;Item 2&lt;/a&gt; &lt;i class=icon&gt;&lt;/i&gt; &lt;/li&gt; &lt;li&gt; &lt;a&gt;Item 3&lt;/a&gt; &lt;i class=icon&gt;&lt;/i&gt; &lt;/li&gt; &lt;li&gt; &lt;a&gt;Item 4&lt;/a&gt; &lt;i class=icon&gt;&lt;/i&gt; &lt;/li&gt; &lt;li&gt; &lt;a&gt;Item 5&lt;/a&gt; &lt;i class=icon&gt;&lt;/i&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>CSS:</strong></p> <pre><code>ul { border: 1px solid green; overflow: hidden; padding: 0; list-style: none; width: 100px; } a { display: inline-block; text-overflow: ellipsis; overflow: hidden; padding-right: 20px; white-space: nowrap; width: 80px; } a:hover { background: gray; } .icon { display: inline-block; float: right; margin-top: -20px; background: yellow; } .icon:before { content: "X"; } .icon:hover:before { background: red; } </code></pre> <p><strong>Question:</strong> How to change CSS (preferably) to be able to hover on "X" to change its background color &amp; be "clickable" in JS but also have the item's background in that line highlighted gray?</p> <p>Right now I cannot event hook "click" event in the "X" because it keeps going under the items.</p> <p><strong>Requirements</strong>:</p> <ol> <li><p>Width for <code>ul</code> is fixed of <code>100px</code></p></li> <li><p>"X" must be in the same line of each <code>li a</code> element and stays in <code>ul</code>'s width</p></li> <li><p>If text in <code>a</code> is too long, it must go under "X" but not show outside box <code>ul</code>. There is no wrap.</p></li> <li><p>Each <code>li a</code> has hardcoded width with <code>ellipsis</code> to show "..." on long text. This width can be changed.</p></li> <li><p>No Javascript. Hardcoded CSS position is OK but less prefer.</p></li> </ol>
 

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