doulao2029 2019-03-25 12:38
浏览 457
已采纳

处理导航栏的溢出

I'm trying to create a website main navigation bar (ideally using only css). I am having trouble dealing with the overflow of links at smaller screen resolutions.

I'm wondering if someone could provide some suggestions for a better way to handle the menu at smaller screen resolutions.

The natural behaviour of the links is to start on a new line so I tried increasing the height of the bar at a smaller media query.

nav, ul, li, a {
    padding: 0 0;
    margin: 0 0
}

nav.navibar {
    width: 100%;
    float: left;
    background-color: #283035;
    height: 60px;
    text-decoration: none;
    white-space: nowrap;
}

nav.navibar .active{
    background-color: #E74310; 
}

ul.navilink{
    list-style:none;
    font-weight:bold;
    margin-bottom: 0;  
    float:left;
    position:relative;
    z-index:5;
}

ul.navilink li{
    float:left;
    position:relative;
}

ul.navilink a{
    display:block;
    padding: 15px 15px;
    color:#ffffff !important;
    text-decoration:none;
    cursor: pointer;
    font-size: 21px;
    font-family: Raleway, Helvetica, "Trebuchet MS", sans-serif;
    text-align: center;
    line-height: 30px;
    /*min-width: 150px;*/
    transition: all 0.3s ease;
}

ul.navilink a:hover{
    background-color: #000;
    color:#fff;
    text-decoration:none;
}

/*--- DROPDOWN ---*/
ul.navilink ul,
ul.navilink li:hover ul li ul{
    list-style:none;
    position:absolute;
    display: none; 
}
ul.navilink ul li{
    padding-top: 0px; 
    float:none;
}

ul.navilink ul a{
    white-space:nowrap; 
    font-size: 16px;
    text-align: left;
}

ul.navilink li:hover ul {
    display: block;
    left: 0;
    z-index: 2147483647;
}

ul.navilink li ul li:hover ul {
    display: block;
    top: 0;
    left:100%; 
    z-index: 2147483647;
}

ul.navilink li:hover a{
    background:#000 !important;
    text-decoration:none;
}

ul.navilink li:hover ul a{
    text-decoration:none;
}

ul.navilink li:hover ul li a:hover{
    background:#f05221 !important;
}

@media only screen and (max-width: 1100px) {
    nav.navibar {
        height: 120px;
        /*overflow: auto;*/
    }
}


<nav class="navibar">
<ul class="navilink">
    <li><a class="active" href="logout">Logout</a></li>
    <li><a>General</a>
        <ul>
            <li><a href="po_search">PO Search</a></li>
        </ul>
    </li>
    <li><a>Inventory</a>
        <ul>
            <li><a href="grazing_rep">Grazing Report</a></li>
            <li><a>PI Checks</a>
                <ul>
                    <li><a href="batch_rotat">Batch Rotation</a></li>
                    <li><a href="dynamic_pi">Dynamic PI Variance</a></li>
                    <li><a href="pi_query_ch">Queries Check</a></li>
                    <li><a href="wrong_check">Wrong Item Checks</a></li>
                </ul>
            </li>
            <li><a>QC Inbound</a>
                <ul>
                    <li><a href="qc_error_ch">QC Error Checks</a></li>
                    <li><a href="qc_process">QC Process</a></li>
                    <li><a href="qc_putaway">QC Putaway</a></li>
                    <li><a href="qc_inbound">QC Stats</a></li>
                    <li><a href="qc_targeted">QC Targeted</a></li>
                </ul>
            </li>
        </ul>
    </li>
</ul>
</nav>
  • 写回答

1条回答 默认 最新

  • dongshiru5913 2019-03-25 17:52
    关注

    Get rid of BOTH the height:60px AND the @media query height:120px.

    The nav div will then automatically be just as tall as it needs for however many rows of links need to wrap at any given moment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境