Proper submenu using only HTML+CSS -


i'm trying write simple html+css menu without absolute positioning or js. problem regarding submenus, either expand current selected item or displace it:

submenu problem

the html straightforward:

<ul id="menu">     <li>item 1</li>     <li>folder 1     <ul>         <li>item 2</li>     </ul>     </li>     <li>item 3</li> </ul> 

and css:

#menu, #menu ul {     border-style: solid;     border-width: 0px;     border-top-width: 1px;     float: left;     list-style: none;     margin: 0px;     padding: 0px;     width: 180px; }  #menu li ul {     background-color: cyan;     display: none;     position: relative;     right: -168px;     width: auto; }  #menu li:hover ul {     display: block; }  #menu li {     border-style: solid;     border-width: 1px;     border-top-width: 0px;     padding: 10px; }  #menu li:hover {     background-color: lightgrey;     font-weight: bold; } 

i thought submenu affect layout after being repositioned, seems not case here. i'm bit @ loss.

using type of menu pattern, should use position:relative on parent li of sub-menu, , position:absolute on ul child menu. allows child element appear outside of layout flow, relative parent.

it's practice put non-position styling on a-tag inside each li , use display:block. difficult style text on "folder 1" without it.

simple example: http://jsfiddle.net/diodeus/jejny/127/


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -