简体   繁体   中英

position fixed header not working on my website

This my website https://bed-sheet-2.myshopify.com/ ,Added fixed position header css

.site-header{z-index:110;position:fixed;width:100%;left:0;}

It's not working on my website, How solve this problem. I search across stackoverflow, no solve.

试试这个: .site-header{z-index:110;position:fixed;top:0px;left:0px;width:100%;}你需要添加px和一个top值。

try this. margin need to set 0px auto .site-header{width:100%; margin:0px auto; position: fixed; top:0px}

Demo for that: https://codepen.io/Guilh/pen/JLKbn

    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
    <script>
        var  mn = $(".main-nav");
        mns = "main-nav-scrolled";
        hdr = $('header').height();

        $(window).scroll(function() {
        if( $(this).scrollTop() > hdr ) {
            mn.addClass(mns);
            } else {
            mn.removeClass(mns);
            }
        });
    </script>

.main-nav{
  position: relative;
}
.main-nav {
  background: #fff;
  height: 80px;
  z-index: 150;
  margin-bottom: -80px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, .4);
}
header,.main-nav-scrolled {
  position: fixed;
  width: 100%;
  top: 0;
}

<nav class="main-nav">
  <a href="#">Nav Link 1</a>
  <a href="#">Nav Link 2</a>
  <a href="#">Nav Link 3</a>
  <a href="#">Nav Link 4</a>
</nav>

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