html - How to fix element at top in CSS? -




i have problem position on css.

i create 3 elements: menu navbar, category bar (to filter content), , content.

it looks this:

*menu `navbar`* home              *category bar* category 1       category 2  *content* lorem ipsum dolor sit amet consectetur adipisicing elit 

when scrolling down, menu show hidden, , category bar fixed on top.

screenshot:

when add css code fix category bar @ top:

ul#filters {     overflow: hidden;     background-color: #333;     position: fixed;     width: 100%; }  ul#filters li {     float: left;     display: block;     color: #f2f2f2;     text-align: center;     padding: 14px 16px;     text-decoration: none;     font-size: 17px; } 

it looks like:

i expected output is:

when loading page success, first image in answer. when user scrolls down, menu hidden, category bar fix top, content @ below category bar.

like this:

note: change menu bar category bar

here code:

ul#filters {      overflow: hidden;      background-color: #333;      position: fixed;      width: 100%;  }    ul#filters li {      float: left;      display: block;      color: #f2f2f2;      text-align: center;      padding: 14px 16px;      text-decoration: none;      font-size: 17px;  }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>  <nav class="navbar navbar-fixed green child-nav">      <div class="container-fluid">          <div class="container">              <!-- collect nav links, forms, , other content toggling -->              <div class="collapse navbar-collapse navbar-ex1-collapse  ">                  <ul class="nav navbar-nav navbar-right">                      <li class="active"><a href="#home" class="scroll">home</a></li>                      <li><a href="#about-us" class="scroll">about us</a></li>                    </ul>              </div><!-- /.navbar-collapse -->          </div>      </div>  </nav>  <div class="container">      <ul id="filters" class="loaiduan clearfix">          <li class="li-selected">              <a href="">category 1</a>          </li>          <li class="li-selected">              <a href="">category 2</a>          </li>      </ul>        <div id="container" class="list">          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>          <p>lorem ipsum dolor sit amet consectetur adipisicing elit. velit temporibus cumque impedit repellendus vero, modi voluptatem id dignissimos assumenda quis fuga suscipit provident ab fugiat dolores @ numquam dolorem adipisci?</p>      </div>  </div>

just use bootstrap class (navbar-fixed-top)

example:

<nav class="navbar navbar-fixed-top green child-nav"> 

hope help!





wiki

Comments

Popular posts from this blog

python - Read npy file directly from S3 StreamingBody -

python - Minimize function with Scipy minimize -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -