html - Responsive Menu - how to? -


i building quite simple responsive menu , ive got trouble rearranging submenus. have 4 menu points. 3 of them have submenus, 1 hyperlink. arrangement of menu bound screen width:

wide screens:

menu point 1 | menu point 2 | menu point 3 | menu point 4   

submenus should appear on bottom of whole thing

mid screens

menu point 1 | menu point 2  menu point 3 | menu point 4 

submenus should appear right underneath chosen menu point, if click on point 2, submenu should appear in between 2 menu lines

smallest screns

menu point 1 menu point 2 menu point 3 menu point 4 

same mid screens, menu should appear right underneath chosen point.

so code menu works mid screens only:

<ul id="mainmenu">   <li>menu point 1 (just hyperlink)</li>   <li>menu point 2</li>   <ul id="submenu2">     <li> ... </li>   </ul>    <li>menu point 3</li>   <li>menu point 4</li>     <ul id="submenu3">       <li> ... </li>     </ul>      <ul id="submenu4">       <li> ... </li>     </ul>   </ul> 

basically lists submenu2, submenu3 , submenu4 have @ different positions different screen sizes, version work smallest screens:

<ul id="mainmenu">   <li>menu point 1 (just hyperlink)</li>   <li>menu point 2</li>   <ul id="submenu2">     <li> ... </li>   </ul>    <li>menu point 3</li>     <ul id="submenu3">       <li> ... </li>     </ul>    <li>menu point 4</li>     <ul id="submenu4">       <li> ... </li>     </ul>   </ul> 

i not sure if right approach!? hint appreciated.

greetings,

michael

you can style element @ given screen size using media queries. this:

@media (max-width: 768px /* or whatever size want */) {    .myelement {       /* styles go here */    } } 

using approach, can change position of sub-menus based on screen size. also, have looked using dropdown menus? here helpful links:

edit:

here's working example of changing position of div based on screen size:

html

<div></div> 

css

div {   position: absolute;   left: 0;   top: 0;   height: 200px;   width: 200px;   background: red; }  @media (max-width: 768px) {   div {     left: auto;     right: 0;   } } 

codepen

hope helps!


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -