简体   繁体   English

如何使导航菜单保持原位

[英]How to make navigation menu stay in place

When structuring a navigation menu with an UL(unordered list), I've noticed when I zoom in and out of the page the list items shift to the right making them come out of line. 当用UL(无序列表)构造导航菜单时,我注意到当放大和缩小页面时,列表项会向右移动,使它们脱节。 How do make them stay in the same place at all times? 如何使他们始终保持在同一地点?

I have added the following at JSFiddle to play with it. 我在JSFiddle中添加了以下内容来使用它。

<div id="navigation">
                     <ul>
                            <font face="Verdana, Geneva, sans-serif">
                            <li > <a href="../index.html" > ANA SƏHIFƏ </a> </li>
                            <li> <a href="../Biography/BiographyAZ.html"> BIOQRAFIYA </a> </li>
                            <li id="active-li"> <a href="#"> XƏBƏRLƏR VƏ HADISƏLƏR </a></li>
                            <li><a> KİTABLAR </a></li>
                            <li> <a> VİDEOLAR </a> </li>
                            <li> <a id="last-item">FOTOLAR</a> </li>
                            </font>
                     </ul>
#navigation {
    width: 900px;
    margin: 0 auto 0px;
}

div#navigation ul li {
    font-size:9px;
    list-style:none;
    background-color:transparent;
    background-color:#FFF;
    float: left;
}
div#navigation ul li:hover {
    background-color:#9C1A35;
}
div#navigation ul li a {
    color:#333333;
    text-decoration:none;
    display: block;
    padding:10px 43px 20px;
}
#navigation ul li a:hover {
    color:#fff;
}
ul {
    padding:0;
}
#active-li {
    background:#9C1A35 !important;
}
#active-li a {
    color:#fff !important;
}
#last-item {
    padding: 10px 42px 20px 42px !important;
}
div#navigation ul li #active {
    background:#9C1A35 !important;
}
div#navigation ul li #active a {
    color:#fff;
}

Most of pages loses their layout when zooming excessively. 过度缩放时,大多数页面都会失去其布局。 This happens when the "zoom only texts" option is enabled in the browser. 在浏览器中启用“仅缩放文本”选项时,会发生这种情况。 here is my suggestions: 这是我的建议:

  • decrease padding-right and padding-left of <a> items to a lower value (43px is too much for your menu). <a>项的padding-rightpadding-left减小到一个较低的值(43px对您的菜单来说太大了)。
  • try giving a height , min-height and max-height to your items, and set overflow:hidden . 尝试为您的商品指定heightmin-heightmax-height ,并设置overflow:hidden This way, the text will stay in it's container box, and won't run out of it. 这样,文本将保留在它的容器框中,并且不会用完。
  • use relative values (percent, em) instead of px to size your elements. 使用相对值(百分比,em)代替px来调整元素的大小。

#navigation { width: 900px; margin: 0 auto 0px; display: inline; }

Figured out a new way to make the nav bar stay in place 找出使导航栏保持原位的新方法

<div id="navigation">
                         <ul>
                                <font face="Verdana, Geneva, sans-serif">
                                <li > <a href="../index.html" > ƏSAS SƏHİFƏ </a> </li>
                                <li> <a href="../Biography/BiographyAZ.html"> BIOQRAFIYA </a> </li>
                                <li id="active-li"> <a href="#"> XƏBƏRLƏR VƏ HADISƏLƏR </a></li>
                                <li><a href="../Books/booksAZ.html"> KİTABLAR </a></li>
                                <li> <a> VİDEOLAR </a> </li>
                                <li> <a id="last-item">FOTOLAR</a> </li>
                                </font>
                         </ul>
                  </div>

    #navigation {
        width: 900px;
        margin: 0 auto 0px;
    }
    div#navigation ul li {
        font-size:9px;
        list-style:none;
        background-color:transparent;
        background-color:#FFF;
        float: left;
        width:150px;
        height:40px;
        text-align:center;
    }
    div#navigation ul li:hover {
        background-color:#9C1A35;
    }
    div#navigation ul li a {
        color:#333333;
        text-decoration:none;
        display: block;
        padding:6px 0px 18px;
        border-left:1px thin black;
        border-right:1px thin black;
    }
    #navigation ul li a:hover {
        color:#fff;
    }
    ul {
        padding:0;
    }
    #active-li {
        background:#9C1A35 !important;
    }
    #active-li a {
        color:#fff !important;
    }
    div#navigation ul li #active {
        background:#9C1A35 !important;
    }
    div#navigation ul li #active a {
        color:#fff;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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