- πΊπΈUnited States todea
I used the following code to get full width sub-menus. This code was borrowed and modified from the hollyhunt site.
I'm using tb_megamenu version 2.0.0-alpha3global.js in my site's theme
dynamically sets the menu width and left offset/** * @file * Global utilities. * */ (function ($, Drupal) { 'use strict'; Drupal.behaviors.yoursite = { attach: function (context, settings) { // Make submenu full browser width. const submenuFullwidthCalc = function () { // Get the Mega menu Level 1 sub menu. $(".tbm-nav > .level-1 > .tbm-submenu").each(function () { // reset to zero so it can be calculated again and again $(this).css("left", 0); const offsettarget = $("body").offset(); // The offset of this submenu. const offsetthis = $(this) //.parent() .parents( "ul" ) // get parent ul instead .offset(); // Calculate the offset. $(this).css("left", offsettarget.left - offsetthis.left); // Set the submenu full width. $(this).css("width", $("body").width()); }); }; $(window).on("load resize", function () { submenuFullwidthCalc(); }); } }; })(jQuery, Drupal);
The below is not necessary but helps with formatting to prevent content from stretching to the edges.
customized tb-megamenu-submenu.html.twig
<div {{ attributes }}> <div class="tb-dropdown-inner"> {% for row in rows %} {{ row }} {% endfor %} </div> </div>
CSS
.tb-dropdown-inner { max-width: 1278px; margin: auto; padding: 0 45px 28px; min-height: 200px; }