How to create a sticky footer inside the LeftNav?

淺唱寂寞╮ 提交于 2019-12-21 17:24:29

问题


I'm trying to create a sticky footer inside the <LeftNav> component, so far unsuccessfully. This is what is needs to look like:

I have tried using position: fixed; bottom: 0 and position: absolute; bottom: 0 on the wrapper of the search field, but when the user scrolls the list items the search field travels up. Like this:

Any idea how to fix this?


回答1:


Position: fixed should work. Without more information about how you have your page setup, it's hard to be more specific. Take a look at this fiddle and see if that helps:

https://jsfiddle.net/kevinlrak/r1mpf1n8/

#search {
  position: fixed;
  background-color: red;
  bottom: 0;
  width: 25%;
}



回答2:


Your <LeftNav> should contain two elements:

  • The first one contains the items and has an overflow-y set to auto (to scroll when too long) and a javascript-set height of the navigation panel height minus the search field height (include paddings!)
  • The second one is position: absolute, bottom: 0 and width: 100% and contains (or is) your #search field

Example where this.props.height is set to my window.innerHeight on window's load and resize events:

<LeftNav>
  <div style={{overflowY: 'auto', height: (this.props.height - 50) + 'px'}}>
    {menuItems}
  </div>
  <div style={{position: 'absolute', bottom: 0, width: '100%'}}>
    {{searchField}}
  </div>
</LeftNav>


来源:https://stackoverflow.com/questions/35662201/how-to-create-a-sticky-footer-inside-the-leftnav

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!