css解決fixed布局不會出現滾動條問題


需求是頁面移動到一定高度時,頂部出現固定的導航欄,並導航欄帶滾動條。

CSS很好實現,但是導航欄飄浮頂部后,滾動條怎么也不顯示,搜了一些資料終於解決了,現做下筆記。

<div class="top_nav">
    <div class="navTab">  
        <label >聚焦新聞</label><label >融媒報道</label><label >各方發聲</label>
        <label >聚焦新聞</label><label >融媒報道</label><label >各方發聲</label>
    </div>
  </div>
.navTab{width:100%;height:0.8rem;line-height:0.8rem;font-size:.32rem;background:#ff0;
display: flex;flex-direction: row;white-space: nowrap;overflow-x: scroll;z-index: 99;}
.navTab label{margin-right: 0.3rem;display: inline-block;}
.fixnav {position: fixed;top: 0; bottom: 0;width: 100%;height: auto;
overflow-x: scroll;overflow-y: hidden;z-index: 99;}
<script >
$(function() {
        $(".top_nav").hide();
        $(window).scroll(function() {
            if($(document).scrollTop() >= 200) {
                $(".top_nav").addClass("fixnav").slideDown();
            } else {
                $(".top_nav").hide();
            }
        })
    })

</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM