Fixed Responsive Top Nav / Off Canvas Nav with Single DOM Element

前端 未结 2 834
灰色年华
灰色年华 2021-01-20 03:36

Let\'s get the fiddles out of the way first (built on the Foundation responsive framework):

Fiddle 1: one nav element, but becomes unfixed when side nav slides out

2条回答
  •  攒了一身酷
    2021-01-20 04:32

    One solution would be to give page position:absolute and change the left positioning instead transforming it.

    .page {
        transition:.3s ease-in-out;
        position:absolute;
        left:0px;
        top:0px;
    }    
    .page.navigating {
        left:250px;
    }
    .page.navigating .top-bar .top-bar-section {
        left:0px;
    }
    

    Demo here

    EDIT

    To make the nave be horizontal on small screen, you'll need to use @media queries. Something like this approximates the result you want

    @media all and (max-width: 310px) {
      .left li {
          display:inline-block;
      }
      .left li a {
      }
      section.top-bar-section {
          width:auto;
      }
      .left li:nth-child(odd) {
          display:none;
      }
      .left li:nth-child(even) a {
          display:inline-block;
          width:auto;
          padding:5px;
          font-size: 50%;
          background:black;
      }
      .page.navigating .top-bar .top-bar-section {
          left:40px;
      }
      .page.navigating {
          left:0px;
      }
      .name h1 {
          float:right;
          font-size:50%;
      }
    }
    

    Updated Demo

提交回复
热议问题