When creating columns of approximately even length with regard to the pages widget, the following constraints and contributing factors are outside the control of the algorithm doing the balancing:
- Number of columns
- Order of menu item groups
- Total number of items
- Relative size (number of child items) of item groups
- Font-size difference between 1st and 2nd-level items
- Text wrapping for items with longer menu text
- If one column must be longer, it should be the left-most
- Performance: we need to generate results in a time frame acceptable to a modern web user
Note: See our guide on how to Achieve Better Balance in your Mega Menu for more help.
Within these constraints, we need to create a single algorithm that will be used for all possible configurations. We have yet to identify an algorithm that will result in ideally balanced columns for all configurations.
- Count the number of total items (at all levels)
- Divide that total by the number of columns
Note: The result is the target number of items in any given column.
- We fill the columns from right to left
At present, the best solution is to adjust the number of columns to that which yields the best result.