"It is possible to create this type of functionality only with CSS?"
Yes. You can achieve this effect with CSS using the HTML attribute tabindex
.
HTML:
<ul class="menu-sanfona">
<li tabindex="0">Item 1
<ul>
<li>Item 1.1</li>
</ul>
</li>
<li tabindex="1">Item 2
<ul>
<li>Item 2.1</li>
</ul>
</li>
</ul>
And the CSS:
.menu-sanfona li ul{
display:none;
}
.menu-sanfona li:focus ul{
display:block;
}
Most complete example: FIDDLE
What the code does is use the attribute tabindex
to make the elements li
can be focused, and then with CSS is defined that when the li
is focused, the ul
his son becomes visible.
Although this solution is interesting for not using Javascript, it is a little limited, since the element is only open while it is focused, IE, if you click on some input
or another item that has focus, the menu would close.
very good! Using css3’s to make up slow sliding effect, leave this option for others to get an extra knowledge!!
– Douglas Bernardino
A question why when I insert a link it closes the square and is not redirected to the page? Great tip! :)
– user30180