Bootstrap 4 fixed top nav and fixed sidebar

前端 未结 2 482
南旧
南旧 2021-02-01 07:58

This is a great example of how to create a navbar with a sidebar. Can anyone modify the code so that the top nav is top-fixed and the sidebar fixed/static with only the main pag

2条回答
  •  臣服心动
    2021-02-01 08:42

    There's a relatively new CSS position property called sticky.

    position: sticky;
    top: 4em;
    

    See how this works, what happens when you scroll to the end of the parent element. Leave height at auto. Reference - https://developer.mozilla.org/en-US/docs/Web/CSS/position

提交回复
热议问题