The problem is the following, there is a horizontal menu. In the code that I specified, displayed as minimized (hidden under the "MENU" button), if my example is expanded (with the "full page" button), the menu will open completely, and that's when it opens all the buttons are shifted to the left, and from the right space remains. And I would like to make it so that everything inside the menu is distributed evenly in the center, without additional spaces and at the same time preserve the adaptability and drop-down lists. Problem screen (highlighted in red): http://s014.radikal.ru/i327/1701/e3/84d9f07a74c8.png The demo menu is here: http://clickmyweb.net/demos/horizontan_menu/ Thank you!
(function($) { $.fn.menumaker = function(options) { var cssmenu = $(this), settings = $.extend({ title: "Menu", format: "dropdown", sticky: false }, options); return this.each(function() { cssmenu.prepend('<div id="menu-button">' + settings.title + '</div>'); $(this).find("#menu-button").on('click', function() { $(this).toggleClass('menu-opened'); var mainmenu = $(this).next('ul'); if (mainmenu.hasClass('open')) { mainmenu.hide().removeClass('open'); } else { mainmenu.show().addClass('open'); if (settings.format === "dropdown") { mainmenu.find('ul').show(); } } }); cssmenu.find('li ul').parent().addClass('parent'); multiTg = function() { cssmenu.find(".parent").prepend('<span class="submenu-button"></span>'); cssmenu.find('.submenu-button').on('click', function() { $(this).toggleClass('submenu-opened'); if ($(this).siblings('ul').hasClass('open')) { $(this).siblings('ul').removeClass('open').hide(); } else { $(this).siblings('ul').addClass('open').show(); } }); }; if (settings.format === 'multitoggle') multiTg(); else cssmenu.addClass('dropdown'); if (settings.sticky === true) cssmenu.css('position', 'fixed'); resizeFix = function() { if ($(window).width() > 768) { cssmenu.find('ul').show(); } if ($(window).width() <= 768) { cssmenu.find('ul').hide().removeClass('open'); } }; resizeFix(); return $(window).on('resize', resizeFix); }); }; })(jQuery); (function($) { $(document).ready(function() { $(document).ready(function() { $("#hmenu").menumaker({ title: "Menu", format: "multitoggle" }); $("#hmenu").prepend("<div id='menu-line'></div>"); var foundActive = false, activeElement, linePosition = 0, menuLine = $("#hmenu #menu-line"), lineWidth, defaultPosition, defaultWidth; $("#hmenu > ul > li").each(function() { if ($(this).hasClass('active')) { activeElement = $(this); foundActive = true; } }); if (foundActive === false) { activeElement = $("#hmenu > ul > li").first(); } defaultWidth = lineWidth = activeElement.width(); defaultPosition = linePosition = activeElement.position().left; menuLine.css("width", lineWidth); menuLine.css("left", linePosition); $("#hmenu > ul > li").hover(function() { activeElement = $(this); lineWidth = activeElement.width(); linePosition = activeElement.position().left; menuLine.css("width", lineWidth); menuLine.css("left", linePosition); }, function() { menuLine.css("left", defaultPosition); menuLine.css("width", defaultWidth); }); }); }); })(jQuery); @font-face{ font-family:'SegoeUILight'; src:url('fonts/segoeuil.eot'); src:url('fonts/segoeuil.eot?#iefix') format('embedded-opentype'), url('fonts/segoeuil.woff') format('woff'), url('fonts/segoeuil.ttf') format('truetype'), url('fonts/segoeuil.svg#web') format('svg'); font-weight:normal; font-style:normal; } body { background: #333; font-family: SegoeUILight; } h1 { text-align: center; color: #FFFFFF; font-family: SegoeUILight; font-weight: 100; } .container { max-width: 1000px; margin: 60px auto; } #hmenu, #hmenu ul, #hmenu ul li, #hmenu ul li a, #hmenu #menu-button { margin: 0; padding: 0; border: 0; list-style: none; line-height: 1; display: block; position: relative; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; } #hmenu:after, #hmenu > ul:after { content: "."; display: block; clear: both; visibility: hidden; line-height: 0; height: 0; } #hmenu #menu-button { display: none; } #hmenu { width: auto; font-family: 'Open Sans', sans-serif; line-height: 1; background: #ffffff; border-radius: 5px; } #menu-line { position: absolute; top: 0; left: 0; height: 3px; background: #009ae1; -webkit-transition: all 0.25s ease-out; -moz-transition: all 0.25s ease-out; -ms-transition: all 0.25s ease-out; -o-transition: all 0.25s ease-out; transition: all 0.25s ease-out; } #hmenu > ul > li { float: left; } #hmenu.align-center > ul { font-size: 0; text-align: center; } #hmenu.align-center > ul > li { display: inline-block; float: none; } #hmenu.align-center ul ul { text-align: left; } #hmenu.align-right > ul > li { float: right; } #hmenu.align-right ul ul { text-align: right; } #hmenu > ul > li > a { padding: 20px; font-size: 14px; text-decoration: none; text-transform: uppercase; color: #000000; -webkit-transition: color .2s ease; -moz-transition: color .2s ease; -ms-transition: color .2s ease; -o-transition: color .2s ease; transition: color .2s ease; } #hmenu > ul > li:hover > a, #hmenu > ul > li.active > a { color: #00AFFF; } #hmenu > ul > li.parent > a { padding-right: 25px; } #hmenu > ul > li.parent > a::after { position: absolute; top: 21px; right: 10px; width: 4px; height: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; content: ""; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -ms-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); -webkit-transition: border-color 0.2s ease; -moz-transition: border-color 0.2s ease; -ms-transition: border-color 0.2s ease; -o-transition: border-color 0.2s ease; transition: border-color 0.2s ease; } #hmenu > ul > li.parent:hover > a::after { border-color: #009ae1; } #hmenu ul ul { position: absolute; left: -9999px; } #hmenu li:hover > ul { left: auto; } #hmenu.align-right li:hover > ul { right: 0; } #hmenu ul ul ul { margin-left: 100%; top: 0; } #hmenu.align-right ul ul ul { margin-left: 0; margin-right: 100%; } #hmenu ul ul li { height: 0; -webkit-transition: height .2s ease; -moz-transition: height .2s ease; -ms-transition: height .2s ease; -o-transition: height .2s ease; transition: height .2s ease; } #hmenu ul li:hover > ul > li { height: 32px; } #hmenu ul ul li a { padding: 10px 20px; width: 160px; font-size: 12px; background: #ffffff; text-decoration: none; color: #000000; -webkit-transition: color .2s ease; -moz-transition: color .2s ease; -ms-transition: color .2s ease; -o-transition: color .2s ease; transition: color .2s ease; } #hmenu ul ul li:hover > a, #hmenu ul ul li a:hover { color: #00AFFF; background-color: rgba(0, 0, 0, 0.4); } #hmenu ul ul li.parent > a::after { position: absolute; top: 13px; right: 10px; width: 4px; height: 4px; border-bottom: 1px solid #000000; border-right: 1px solid #000000; content: ""; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -ms-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); -webkit-transition: border-color 0.2s ease; -moz-transition: border-color 0.2s ease; -ms-transition: border-color 0.2s ease; -o-transition: border-color 0.2s ease; transition: border-color 0.2s ease; } #hmenu.align-right ul ul li.parent > a::after { right: auto; left: 10px; border-right: 0; border-top: 1px solid #000000; border-left: 1px solid #000000; } #hmenu ul ul li.parent:hover > a::after { border-color: #00AFFF; } @media all and (max-width: 768px), only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min--moz-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (-o-min-device-pixel-ratio: 2/1) and (max-width: 1024px), only screen and (min-device-pixel-ratio: 2) and (max-width: 1024px), only screen and (min-resolution: 192dpi) and (max-width: 1024px), only screen and (min-resolution: 2dppx) and (max-width: 1024px) { #hmenu { width: 100%; } #hmenu ul { width: 100%; display: none; } #hmenu.align-center > ul, #hmenu.align-right ul ul { text-align: left; } #hmenu ul li, #hmenu ul ul li, #hmenu ul li:hover > ul > li { width: 100%; height: auto; border-top: 1px solid rgba(120, 120, 120, 0.15); } #hmenu ul li a, #hmenu ul ul li a { width: 100%; } #hmenu > ul > li, #hmenu.align-center > ul > li, #hmenu.align-right > ul > li { float: none; display: block; } #hmenu ul ul li a { padding: 20px 20px 20px 30px; font-size: 12px; color: #000000; background: none; } #hmenu ul ul li:hover > a, #hmenu ul ul li a:hover { color: #000000; } #hmenu ul ul ul li a { padding-left: 40px; } #hmenu ul ul, #hmenu ul ul ul { position: relative; left: 0; right: auto; width: 100%; margin: 0; } #hmenu > ul > li.parent > a::after, #hmenu ul ul li.parent > a::after { display: none; } #menu-line { display: none; } #hmenu #menu-button { display: block; padding: 20px; color: #333; cursor: pointer; font-size: 12px; text-transform: uppercase; } #hmenu #menu-button::after { content: ''; position: absolute; top: 20px; right: 20px; display: block; width: 15px; height: 2px; background: #000000; } #hmenu #menu-button::before { content: ''; position: absolute; top: 25px; right: 20px; display: block; width: 15px; height: 3px; border-top: 2px solid #000000; border-bottom: 2px solid #000000; } #hmenu .submenu-button { position: absolute; z-index: 10; right: 0; top: 0; display: block; border-left: 1px solid rgba(120, 120, 120, 0.15); height: 52px; width: 52px; cursor: pointer; } #hmenu .submenu-button::after { content: ''; position: absolute; top: 21px; left: 26px; display: block; width: 1px; height: 11px; background: #000000; z-index: 99; } #hmenu .submenu-button::before { content: ''; position: absolute; left: 21px; top: 26px; display: block; width: 11px; height: 1px; background: #000000; z-index: 99; } #hmenu .submenu-button.submenu-opened:after { display: none; } } .main { text-align: center; } .block { display: inline-block; vertical-align: top; text-align: left; /* Если надо выравнить по левому краю внутри каждого блока */ } <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/2.0.0/knockout-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.3.9/d3.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.7/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <!doctype html> <html lang=''> <head> <meta charset='utf-8'> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="css/styles.css" /> <link rel="stylesheet" type="text/css" href="css/main.css" /> <script src="/js/jquery-1.11.1.min.js" type="text/javascript"></script> <script src="/js/hmenu.js"></script> <title>Адаптивное горизонтальное меню</title> </head> <body> <div class="main"> <div class="container"> <h1>Горизонтальное адаптивное выпадающее меню</h1> <div class="block" id='hmenu'> <ul> <li><a href='#'>Главная</a> </li> <li class='active parent'><a href='#'>Услуги</a> <ul> <li><a href='#'>Что-то</a> </li> <li><a href='#'>Услуги</a> </li> <li><a href='#'>О Нас</a> </li> <li><a href='#'>контент</a> </li> </ul> </li> <li><a href='#'>О Нас</a> </li> <li><a href='#'>Контакты</a> </li> <li><a href='#'>Регистрация</a> </li> </ul> </div> </div> </div> </body> <html>