Make a nav bar stick

前端 未结 11 1314
别跟我提以往
别跟我提以往 2020-11-29 19:44

Make a nav bar stick Make a nav bar stick Make a nav bar stick Make a nav bar stick Make a nav bar stick Make a nav bar stick Make a nav bar stick Make a nav bar stick Make

11条回答
  •  渐次进展
    2020-11-29 20:02

    You can do it with CSS only by creating your menu twice. It's not ideal but it gives you the opportunity have a different design for the menu once it's on top and you'll have nothing else than CSS, no jquery. Here is an example with DIV (you can of course change it to NAV if you prefer):

    THIS IS MY HIDDEN MENU
    MY BODY

    And then have the following CSS:

    #hiddenmenu {
    position: fixed;
    top: 0;
    z-index:1;
     }
    #header {
    top: 0;
    position:absolute;
    z-index:2;
     }
    #body {
    padding-top: 80px;
    position:absolute;
    z-index: auto;
     }
    

    Here is a fiddle for you to see: https://jsfiddle.net/brghtk4z/1/

提交回复
热议问题