Make scrolling sidebar stop at footer

前端 未结 5 1178
陌清茗
陌清茗 2020-12-09 06:20

I\'m currently using the following:

http://jsfiddle.net/0mLzseby/469/

To make my sidebar follow down the page. I have quite a large footer though and I\'d li

5条回答
  •  暖寄归人
    2020-12-09 07:11

    You don't need to use javascript for this. You can do this using CSS only:

    position: sticky;
    

    body{
      padding: 0 20px;
    }
    #content {
      height: 1200px;
    }
    header {
      width: 100%;
      height: 150px;
      background: #aaa;
    }
    main {
      float: left;
      width: 65%;
      height: 100%;
      background: #444;
    }
    aside {
      float: right;
      width: 30%;
      height: 500px;
      position: sticky;
      top: 100px;
      background: #777;
    }
    footer {
      width: 100%;
      height: 300px;
      background: #555;
    }
    
      
    Header
    Content
    Footer

提交回复
热议问题