html - Flex item with justify-content: space-between is not displaying correctly -
i have menu bar sub-menus. want on same line menu "account" or "profile" link on right, , want pure css3/flex.
but guess there wrong in css code because last link ("account") diplaying under main menu, justify-content: space-between
nav element not working. how can ?
here code :
nav { font-size: 20px ; background-color: white; display: flex; flex-direction: row; justify-content: space-between; } nav ul { display: flex; flex-direction: row; margin: 0; padding: 0 ; position: absolute; background-color: white; list-style-type: none; } nav ul li { padding: 0; margin: 0; } nav ul li ul { display: none; margin: 0; padding: 0; box-shadow: 3px 3px 3px 0px #dddddd; background-color: white; } nav ul li:hover ul{ display: block; } nav { color: #333; display: block; margin: 0; padding: 10px 20px; text-decoration: none; } nav a:hover { background-color: #ddd; }
<nav> <ul> <li><a href="#">menu1</a> <ul> <li><a href="#">submenu</a></li> <li><a href="#">another longer submenu here</a></li> <li><a href="#">yet submenu</a></li> <li><a href="#">etc. etc.</a></li> </ul> </li> <li><a href="#">menu2</a></li> <li><a href="#">menu3</a> <ul> <li><a href="#">my submenu 1</a></li> <li><a href="#">my submenu 2</a></li> <li><a href="#">my submenu 3</a></li> <li><a href="#">my submenu 4</a></li> <li><a href="#">my submenu 5</a></li> <li><a href="#">my submenu 6</a></li> <li><a href="#">my submenu 7</a></li> <li><a href="#">my submenu 8</a></li> </ul> </li> <li><a href="#">menu4</a> </li> </ul> <a href="#">account</a> </nav>
ok, found error.
nav ul { position: absolute; }
should not positionned here, here :
nav ul li ul { position: absolute; }
so snippet fixed (hope else)...
nav { font-size: 20px ; background-color: white; display: flex; flex-direction: row; justify-content: space-between; } nav ul { display: flex; flex-direction: row; margin: 0; padding: 0 ; background-color: white; list-style-type: none; } nav ul li { padding: 0; margin: 0; } nav ul li ul { display: none; margin: 0; padding: 0; box-shadow: 3px 3px 3px 0px #dddddd; background-color: white; position: absolute; } nav ul li:hover ul{ display: block; } nav { color: #333; display: block; margin: 0; padding: 10px 20px; text-decoration: none; } nav a:hover { background-color: #ddd; }
<nav> <ul> <li><a href="#">menu1</a> <ul> <li><a href="#">submenu</a></li> <li><a href="#">another longer submenu here</a></li> <li><a href="#">yet submenu</a></li> <li><a href="#">etc. etc.</a></li> </ul> </li> <li><a href="#">menu2</a></li> <li><a href="#">menu3</a> <ul> <li><a href="#">my submenu 1</a></li> <li><a href="#">my submenu 2</a></li> <li><a href="#">my submenu 3</a></li> <li><a href="#">my submenu 4</a></li> <li><a href="#">my submenu 5</a></li> <li><a href="#">my submenu 6</a></li> <li><a href="#">my submenu 7</a></li> <li><a href="#">my submenu 8</a></li> </ul> </li> <li><a href="#">menu4</a> </li> </ul> <a href="#">account</a> </nav>
Comments
Post a Comment