简体   繁体   中英

Resize fixed navigation menu

I have a big problem with a fixed menu when browser is resized because the li are overlapping and leaving out the section in which they are defined :(. So I was thinking about two options that I could use: 1: entire menu has a fixed width in pixels and not in % and when browser is resized to scroll that menu in right-left. 2: li are rearranged in the same section defined with border.

Till now I was not able to do nothing because if I use overflow to scroll my menu left and right when browser is resized is not working. If someone can give me a solution for this sultry issue I'll be grateful :)

Here is a page test: http://mainpage.ueuo.com/Pagina%20start.htm

Thank you.

Add min-width: 1000px (or more... your menu is really too long imho)

to both your fixed #header and to body element.

This will make overflow-x work (with no need to specify it).

Or u can use a script to rewrite your padding and font-size properties:

function renderMenuCorection(){
                if ($('#containerHeader').exists()) {
                    var resizeObject = {

                        '0-640': '9px,2px,-3px',
                        '640-800': '10px,2px,-5px',
                        '800-1024': '10px,8px,-13px',
                        '1024-1300': '12px,12px,-13px',
                        '1300-2000': '14px,20px,-21px'
                    }

                    var win = $(window);
                    var win_width = win.width();

                    if (win_width > 0 && win_width <= 640) {
                        var value = getValueByKey(resizeObject, '0-640')
                        modifayMenu(value);
                        console.log(win_width + ' : ' + value);
                    }
                    else 
                        if (win_width > 640 && win_width <= 800) {
                            var value = getValueByKey(resizeObject, '640-800')
                            modifayMenu(value);
                            console.log(win_width + ' : ' + value);
                        }
                        else 
                            if (win_width > 800 && win_width <= 1024) {
                                var value = getValueByKey(resizeObject, '800-1024')
                                modifayMenu(value);
                                console.log(win_width + ' : ' + value);
                            }
                            else 
                                if (win_width > 1024 && win_width <= 1300) {
                                    var value = getValueByKey(resizeObject, '1024-1300')
                                    modifayMenu(value);
                                    console.log(win_width + ' : ' + value);
                                }

                                else 
                                    if (win_width > 1300 ) {
                                        var value = getValueByKey(resizeObject, '1300-2000')
                                        modifayMenu(value);
                                        console.log(win_width + ' : ' + value);
                                    }
                }
            }
          function modifayMenu(value){
            var vals = value.split(',')
                $('#containerHeader').find('.roundMenuLi').each(function(index, item){
                    $(item).find('a').css('font-size', vals[0]);
                    $(item).css('padding-right', vals[1]);
                    $(item).css('padding-left', vals[1]);
                    $(item).find('ul').css('margin-left', vals[2]);
              });

            }
          function getValueByKey(obj, myKey){

                $.each(obj, function(key, value){

                    if (key == myKey) {
                        returnValue = value;
                    }
                });
                return returnValue;
            }

-first declare your resolutions 0-600 ... 1300-2000 and in modifayMenu function set your properties for css: 0position-font,1position-padding left&right,2position margin left for secon ul level.

call script on:

<body onresize="renderMenuCorection();" onload="renderMenuCorection();">
#firstUl > li {
    display:inline-block; 
    vertical-align:top; 
    display:inline; /* display:inline & zoom:1 for ie7 */ 
    zoom:1;
}

remove height from ul & ul container, remove height from containerHeader use padding top & bottom to keep gap between menu & container

put

overflow:hidden;

in the inline style of the dividio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM