Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is good practice to prevent the excessive use of JavaScript when you can reach the same result with CSS but sometimes it is necessary to change DOM elements and apply some "tricks" to get it to work and that is not so good at all.</p> <p>Look at this <strong><a href="http://jsfiddle.net/UWYcv/2/" rel="nofollow">DEMO</a></strong> with only CSS3. You can do a similar effect but with hover event instead of a click event. You can change <code>:hover</code> to <code>:active</code> but that will only work if you keep pressing mouse button inside the DIV elements.</p> <p>This <code>.menuItem:hover + .subItem</code> CSS rule is showing the next <code>.subItem</code> element of hovered <code>.menuItem</code></p> <p>Since you do not want to use JavaScript events, you can't apply a class to the element. If you did so it would be easier. This way, <strong>using only CSS</strong>, you can apply some tricks like using checkboxes instead of DIV elements and use their <code>:checked</code> property as CSS rules to show the sublinks.</p> <p>Something like this:</p> <pre><code>&lt;label for="m1" class="menuItem"&gt;Click Item 1&lt;/label&gt; &lt;input id="m1" class="cb" type="checkbox"&gt; &lt;div class="subItem"&gt;Hi there&lt;/div&gt; &lt;label for="m2" class="menuItem"&gt;Click Item 2&lt;/label&gt; &lt;input id="m2" class="cb" type="checkbox"&gt; &lt;div class="subItem"&gt;Some text over here.&lt;/div&gt; &lt;label for="m3" class="menuItem"&gt;Click Item 3&lt;/label&gt; &lt;input id="m3" class="cb" type="checkbox"&gt; &lt;div class="subItem"&gt;Tnx for clicking&lt;/div&gt; .cb { display: none; } .cb:checked + .subItem { display: block; } </code></pre> <p><strong><a href="http://jsfiddle.net/RF6gT/" rel="nofollow">Working demo</a></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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