Is this possible submenu positioning using CSS?

Apologizing for a vague question, I cannot come up with a brief, descriptive one.

I am making a dropdown menu from unordered lists that look something like this.

<ul id="menu">
    <li>Menu Item</li>
    <li>Menu Item
        <ul class="sub-menu">
            <li>Sub Menu Item</li>        
            <li>Sub Menu Item</li>
        </ul>
    </li>
    <li>Menu Item</li>
</ul>

However, I am wondering if this kind of positioning behavior is possible (images explain this better, I think)

Case 1

A submenu focuses on it containing a list item, but is wider than the list item. Sub menu is centred to it's containing list item

Case 2

The submenu should be centered, but there is not enough left space in the root list, so it rests on the edge of the left edge of the root lists. submenu wont extend past the left edge root-list

Case 3

Like case 2, but this time it is the right edge. submenu wont extend past the right edge of the root-list

I think it can be broken down into two complex CSS issues.

  • How to center a submenu on a container, even though it is wider than the container.
  • , .

Javascript, . , CSS.

JSFiddle , , - .

+5
1

http://jsfiddle.net/AxnVU/28/

div, , , , text-align.

, ul div.submenu, .

: div, ( ), . , , text-align, , .

http://jsfiddle.net/AxnVU/69/

, . ( ), 300% , (-100% , ). , .

+2

All Articles