CSS Dropdown menu with horizontal submenu

10,557

Solution 1

You problem is that you are placing the sub-menu absolutly positioned to the parent li. But the parent li has a small width.

The solution is to place the sub-menu absolutely positioned to the menu wrapper.

See this link with a working presentation!

UPDATE YOUR CSS:

#menu {
  width: 820px;
  height: 60px;
  margin: 0 auto;
  padding: 0px 40px;
  position: relative;
}

#menu li {
  float: left;
}

#menu ul ul {
  list-style-type: none;
  position: absolute;
  z-index: 500;
  left: 0;
  right: 0;
}

AND DELETE THIS CSS:

#menu ul li ul li #jackie_spencer{
  display: inline;
  position: absolute;
  top: 20px;
  left: 0;
  width: 100px;    
  color: #FFF;
}

Note:

You can view the source and check the CSS:

  • where it reads "updated", some definitions were changed!
  • Where it reads "updated, deleted", the declarations were deleted.

Solution 2

I took a look at your page, and the reason your submenu is vertical is the submenu <ul> is too narrow: its width is the same as enclosing <li>. You should set a width on it to make it take up all available space.

Making it left-aligned with the parent element and right-aligned with the right end of the menu bar is tricky. You might just want to set it to something wide enough to hold everything you know will be in it, and assume there won't be any reflow.

You also could use some JavaScript to calculate the right positions for it. JQuery is good for that. You'd only need to set those once when the page is first loaded, as part of $(document).ready().

Share:
10,557
user1411281
Author by

user1411281

Updated on June 13, 2022

Comments

  • user1411281
    user1411281 almost 2 years

    I have the following site http://jsfiddle.net/Me4fw/4/ in which I am attempting to implement a horizontal css drop down menu that has a submenu which is also horizontal. I have tried everything but nothing seems to get the submenu items to sit inline with each other. All I can get them to do is mash up ontop of each other and be ugly/unreadable.