skip to Main Content

I want to keep the sticky header to remain at the top of my #main div.

Here is my js fiddle link. Even in responsive mode. I tried below code but its not working.

@import "bootstrap-sprockets";
@import "bootstrap";
@import "font-awesome";
@import "navbar";
body,
html {
  height: 100%;
  overflow: hidden;
  position: relative;
}

body {
  padding: 10px;
}

.row-offcanvas {
  height: 100%;
  padding: 5% 0px 5% 0px;
}

#sidebar {
  width: inherit;
  min-width: 220px;
  max-width: 220px;
  background-color: black;
  float: left;
  height: 100%;
  position: relative;
  overflow: hidden;
}

#main {
  height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: white;
}

#sticky {
  background-color: green;
}


/*
 * off Canvas sidebar
 * --------------------------------------------------
 */

@media screen and (max-width: 768px) {
  .row-offcanvas {
    position: relative;
    -webkit-transition: all 0.25s ease-out;
    -moz-transition: all 0.25s ease-out;
    transition: all 0.25s ease-out;
    width: calc(100% + 230px);
    margin-top: 35px;
  }
  .visible-xs {
    padding-top: 10px;
  }
  .row-offcanvas-left {
    left: -230px;
  }
  .row-offcanvas-left.active {
    left: 0;
  }
  .sidebar-offcanvas {
    position: absolute;
    top: 0;
  }
}
<link href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css" rel="stylesheet" />
<div class="row-offcanvas row-offcanvas-left">
  <div id="sidebar" class="sidebar-offcanvas">
    <div class="col-md-12">
      <h2>
        Sidebar
      </h2>
    </div>
  </div>
  <div id="main">
    <div id="sticky">
      sticky header
    </div>
    <div class="col-md-12">
      <p class="visible-xs">
        <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"><i class="glyphicon glyphicon-chevron-left"></i></button>
      </p>
      <div class="row">
        <h2>
          main content
          <br/> main content
          <br/> main content
          <br/>main content
          <br/>main content
          <br/>main content
          <br/>main content
          <br/>main content
          <br/>
        </h2>
      </div>
    </div>
  </div>
</div>
<!--/row-offcanvas -->

Could anyone help me? Appreciate your help in advance.
Thanks

2

Answers


  1. Chosen as BEST ANSWER

    While resizing output window - sticky header width is varying. I want to make that stick with main content.I mean the sticky div must fit along with main div.


  2. Add below CSS to id #sticky

    position: fixed;
    width: 100%;
    z-index: 99;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search