wp-bootstrap-navwalker icon indicating copy to clipboard operation
wp-bootstrap-navwalker copied to clipboard

Including a wrapper div around the dropdown-menu

Open Chris-AXA opened this issue 12 years ago • 7 comments

I have question about how to include a wrapper div around the dropdown ul which I need for my design.

I figured out that adding to the output in function start_lvl will work. For example:

$output .= "\n$indent<div class=\"dropdown-container\">\n$indent<ul role=\"menu\" class=\" dropdown-menu\">\n";  

But I can't figure out where to close the div tag. I can't seem to find where the ul tag gets closed either.

I am sorry if this is not the right place to put this. I tried contacting the developer of the Wordpress template I'm using and he pointed me here instead. Any help would be much appreciated.

Chris-AXA avatar Mar 21 '14 09:03 Chris-AXA

I will take a look at this for you. Im just curious why you would want to wrap another div around the <ul>? I may be able to suggest a way to do what your looking for purely with CSS.

The </ul> is actually auto closed by WordPress's core walker class as, wp-bootstrap-navwalker does not fully replace the standard WordPress walker, is simply extends the default walker with additional formatting.

SideQuestDIY avatar Mar 21 '14 15:03 SideQuestDIY

Thanks for responding so quickly.

Reason why is because I have the Main Nav in a container and I want the background of dropdown to span the full width of the page (outside of the main container) but the actual ul should be centered just like the main nav. Only way to achieve that is put a wrapper div around the dropdown and have that stretch to full width with a containing dropdown ul centered within.

A bit convoluted, I hope you understand. I would welcome a pure CSS solution, but as far as I know there isn't one for my specific problem.

Chris-AXA avatar Mar 21 '14 15:03 Chris-AXA

Interesting. I about 80% understand what you are trying to achieve. Do you have a screen shot of your mock you can share?

SideQuestDIY avatar Mar 21 '14 16:03 SideQuestDIY

fireshot screen capture 004 - wpstable i just another wordpress site - wpstable_dev would this be similar to what you are looking for? if so, this would be done with only css -no additional markup needed> this my rough css of the screenshot at 1350px:

.navbar-default {
background-color: purple; <--
border-color: #e7e7e7;
}
.navbar-default .navbar-brand {
color: yellowgreen; <--
}
.navbar-default .navbar-nav>li>a {
color: yellowgreen; <--
}
.dropdown-menu {
position: fixed !important; <-- //enables the full width property
top: 49px; <-- align to nav heads height
left: 0;
z-index: 1000;
display: none;
float: left;
min-width: 160px;
width: 100%; <-- make it full
padding: 5px 0;
margin: 2px 0 0;
list-style: none;
font-size: 14px;
background-color: yellowgreen; <--
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
box-shadow: 0 6px 12px rgba(0,0,0,.175);
background-clip: padding-box;
}
.dropdown-menu>li>a {
display: block;
padding: 3px 106px; <-- align the dropdown link to nav header
clear: both;
font-weight: 400;
line-height: 1.428571429;
color: #333;
white-space: nowrap;
}

I've marked the changed bootstrap css properties with an arrow. and you will need to adjust the properties within each media query to keep the mobile dropdowns in their neat right place.

cristovaov avatar Mar 21 '14 23:03 cristovaov

Hey thanks for the comments. Unfortunately Cristov your CSS would come close but not fully achieve what I want. Here is a mockup of what I need: http://i.imgur.com/x9D2B8z.png?1 The red lines show where the main nav container is. In order to get the li in the dropdown in columns I need the dropdown ul width to be defined and centered and an outer container div to stretch to the full width.

Chris-AXA avatar Mar 24 '14 09:03 Chris-AXA

Never mind I found the answer! Adding this after the display_element function did the trick.

function end_lvl(&$output, $depth=0, $args=array()) {
        $output .= "</ul></div>\n";
    }

Chris-AXA avatar Mar 26 '14 12:03 Chris-AXA

@Chris-AXA cool, glad you made it work your way!

cristovaov avatar Mar 27 '14 23:03 cristovaov