Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center drop down of main menu dynamically

I want to have the class="children" centered in the middle of the page container preferably using css only but if it is not possible you can provide the best js answer. Currently it is just a normal drop down but I want to use it as a mega menu. If I have to add another div structure that's fine.

<div class="main-navigation-wrapper">
    <div class="nav pull-left">
        <div class="menu-main-menu-container">
            <ul id="menu" class="menu no-dropdown">
                <li class="menu-item">
                    <a href="#">Blog</a>
                    <div class="children">
                        --- Children items are here
                    </div>
                 </li>
             </ul>
         </div>
    </div>
</div>

I have seen some other examples but have attempted a few and none of them center it. I want to find a dynamic approach to where no matter the location of the link in the menu it always centers the menu in the container.

enter image description here

enter image description here

EDIT: Fiddle found here http://jsfiddle.net/YzJ4h/

like image 700
Anthony Russo Avatar asked May 17 '14 05:05

Anthony Russo


1 Answers

The simplest would be to add this CSS to horizontaly center your mega menu items :

CSS :

#menu li, .second-menu li {
    display:inline-block;
    position:relative;
}
#menu > li.mega_width {
    display:inline-block;
    position:static;
}
#menu > li.mega_width > .children {
    position:absolute;
    left:0;
    right:0;
    top:auto;
    margin:auto;
}

DEMO

like image 195
web-tiki Avatar answered Oct 13 '22 12:10

web-tiki