调整固定导航菜单的大小

时间:2013-01-24 08:44:23

标签: javascript jquery html css

当浏览器调整大小时,我的固定菜单有一个大问题,因为li是重叠的,并且省略了定义它们的部分:(。 所以我在思考我可以使用的两个选项: 1:整个菜单具有固定的宽度(以像素为单位)而不是%,当浏览器调整大小以在左右滚动该菜单时。 2:li在与边界定义的相同部分重新排列。

直到现在我无法做任何事情,因为如果我在浏览器调整大小时使用溢出来左右滚动我的菜单不起作用。 如果有人能为我解决这个闷热的问题,我将不胜感激:)

这是一个页面测试: http://mainpage.ueuo.com/Pagina%20start.htm

谢谢。

4 个答案:

答案 0 :(得分:2)

添加min-width: 1000px(或更多...您的菜单真的太长了imho)

指向固定的#headerbody元素。

这将使overflow-x起作用(无需指定)。

答案 1 :(得分:2)

或者您可以使用脚本重写填充和字体大小属性:

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;
            }

- 首先声明您的分辨率0-600 ... 1300-2000并在modifayMenu函数中设置您的属性为css:0position-font,1position-padding left&amp; right,2position margin for secon ul level。

调用脚本:

<body onresize="renderMenuCorection();" onload="renderMenuCorection();">

答案 2 :(得分:1)

#firstUl > li {
    display:inline-block; 
    vertical-align:top; 
    display:inline; /* display:inline & zoom:1 for ie7 */ 
    zoom:1;
}

从ul&amp;移除高度ul容器,从containerHeader移除高度使用padding top&amp;底部以保持菜单和容器

答案 3 :(得分:0)

overflow:hidden;

在dividio的内联样式中