CSS fixed list header using one scroll bar

johnnyshrewd

I basically want to have a scrollable list with a fixed header. The only thing is that I want the scroll bar to extend the full height of the parent, but only scroll nav-items (keeping the logo fixed).

I am currently doing this:

<div className="home-page-nav">
   <div className="logo"></div>

   <div className="nav-items">
     <div className="nav-item"></div>
     ....
   </div>
</div>

And CSS:

.home-page-nav {
   overflow:auto;
   overflow-y:scroll;
}

.logo {
   position: fixed;
}

Here is what I want to achieve:

enter image description here

Huangism

You can use position: sticky;

below is an example, I specified a height for the overflow container so you can actually scroll the content within

You can read more on it https://developer.mozilla.org/en-US/docs/Web/CSS/position and make sure to check browser support

A stickily positioned element is an element whose computed position value is sticky. It's treated as relatively positioned until its containing block crosses a specified threshold (such as setting top to value other than auto) within its flow root (or the container it scrolls within), at which point it is treated as "stuck" until meeting the opposite edge of its containing block.

.home-page-nav {
  overflow: auto;
  overflow-y: scroll;
  height: 400px;
}

.logo {
  position: -webkit-sticky;
  position: sticky;
  background-color: green;
  top: 0;
}

.nav-item {
  height: 40px;
  margin-bottom: 10px;
  background-color: grey;
}
Document
<br/>
<br/>
<br/><br/>
<div class="home-page-nav">
  <div class="logo">I am logo</div>

  <div class="nav-items">
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
    <div class="nav-item"></div>
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTML fixed header bar when scroll

From Dev

position:fixed navigation header overlapping browser scroll bar when using overflow-x

From Dev

Css: scroll table with fixed header with multiple tbody

From Dev

Css: scroll table with fixed header with multiple tbody

From Dev

CSS Fixed column width with scroll bar

From Dev

Can We Scroll fixed 3 List item item on one time scroll using iscroller

From Dev

Make Fixed Gridview Header to ignore browser Scroll-bar JQuery

From Dev

Fixed header and hide (scroll) address bar mobile browser with MDL framework?

From Dev

html - fixed scroll header

From Dev

Fixed Horizontal Scroll Bar

From Dev

Fixed side bar on scroll

From Dev

Fixed table header scroll both horizontal and vertical CSS ONLY

From Dev

HTML table fixed header by using css

From Dev

Fixed header jump after using css transition

From Dev

HTML table fixed header by using css

From Dev

Create fixed header using html and css

From Dev

Fixed navigation bar would not work even using position: fixed in css

From Dev

Scroll to anchor position with fixed header

From Dev

account for fixed header with smooth scroll

From Dev

Navigation bar fixed after scroll?

From Dev

ListView: show fixed header on top of scroll bar (or drawing a view on top of another with dispatchDraw)

From Dev

Make one column fixed with horizontal scroll using Bootstrap?

From Dev

Bootstrap fixed side bar and header

From Dev

CSS Fixed Header

From Dev

CSS Fixed Header

From Dev

how to make content to be fixed inside scroll div using only css?

From Dev

how to make content to be fixed inside scroll div using only css?

From Dev

Fixed CSS Navigation Bar

From Dev

Problem in creating a sticky/fixed nav bar using css

Related Related

  1. 1

    HTML fixed header bar when scroll

  2. 2

    position:fixed navigation header overlapping browser scroll bar when using overflow-x

  3. 3

    Css: scroll table with fixed header with multiple tbody

  4. 4

    Css: scroll table with fixed header with multiple tbody

  5. 5

    CSS Fixed column width with scroll bar

  6. 6

    Can We Scroll fixed 3 List item item on one time scroll using iscroller

  7. 7

    Make Fixed Gridview Header to ignore browser Scroll-bar JQuery

  8. 8

    Fixed header and hide (scroll) address bar mobile browser with MDL framework?

  9. 9

    html - fixed scroll header

  10. 10

    Fixed Horizontal Scroll Bar

  11. 11

    Fixed side bar on scroll

  12. 12

    Fixed table header scroll both horizontal and vertical CSS ONLY

  13. 13

    HTML table fixed header by using css

  14. 14

    Fixed header jump after using css transition

  15. 15

    HTML table fixed header by using css

  16. 16

    Create fixed header using html and css

  17. 17

    Fixed navigation bar would not work even using position: fixed in css

  18. 18

    Scroll to anchor position with fixed header

  19. 19

    account for fixed header with smooth scroll

  20. 20

    Navigation bar fixed after scroll?

  21. 21

    ListView: show fixed header on top of scroll bar (or drawing a view on top of another with dispatchDraw)

  22. 22

    Make one column fixed with horizontal scroll using Bootstrap?

  23. 23

    Bootstrap fixed side bar and header

  24. 24

    CSS Fixed Header

  25. 25

    CSS Fixed Header

  26. 26

    how to make content to be fixed inside scroll div using only css?

  27. 27

    how to make content to be fixed inside scroll div using only css?

  28. 28

    Fixed CSS Navigation Bar

  29. 29

    Problem in creating a sticky/fixed nav bar using css

HotTag

Archive