简体   繁体   English

定位固定侧边栏,溢出滚动不滚动到底部

[英]Position fixed sidebar with overflow scroll not scrolling to bottom

I am trying to implement a fixed sidebar with dynamically loaded items onclick a Load More button. 我正在尝试使用动态加载的项目实现固定侧边栏,然后单击“ Load More按钮。

I am attaching a class fixed to the parent sidebar div and innerscroll to the inner div to make it scrollable. 我附加一个fixed到父侧边栏div的类和innerscroll到内部div以使其可滚动。

.fixed{position:fixed;top:0; bottom:0}
.innerscroll{overflow-y:scroll;height:100%}

Sidebar code 边栏代码

<div id="sidebar" class="sticky">
 <div class="cat-select"><select>
...
</select></div>
  <div class="item">
<section id="ajax-load-more">
... ajax content...
</section>      
  </div>
</div>

Can't figure out why after loading the next set of posts I can't scroll to the end such that the load-more button is visible. 无法弄清楚为什么在加载下一组帖子后我无法滚动到末尾 ,以便加载更多按钮可见。

OK, I got it. 好,我知道了。 Just add two lines in your .fixed class: 只需在.fixed类中添加两行:

.fixed {
   position: fixed;
   top: 0;
   bottom: 45px; /* added */
   min-height: 0 !important; /* added */
}

And this will work exactly as you expected. 这将完全按照您的预期工作。 Good luck! 祝好运!

I believe it's because you have the inner-scroll div set to height:100%. 我相信这是因为你将内部滚动div设置为高度:100%。 I changed it to height: 90% - the button is now visible, and your content is still scrollable. 我将其更改为高度:90% - 按钮现在可见,您的内容仍可滚动。 I don't know why setting it to height 100% would knock out your button, though. 我不知道为什么将它设置为高度100%会淘汰你的按钮。

You need to adjust a few things to get it to work. 你需要调整一些东西才能让它发挥作用。

First thing is your div sidebar to the class stick 首先是你的div侧栏到班级

<div id="sidebar" class="sticky fixed">

Once you've done that then simply modify the CSS for #sidebar line 22 style.css your saying 1000px but really 一旦你完成了这个,那么只需修改#sidebar第22行style.css的CSS你说1000px,但真的

#sidebar {
min-height: 50%;
max-height: 95%;
}

This makes it work on my side. 这使它适合我。 Also I might be wrong and you might not need to do the DIV so try the CSS first then try the DIV and the CSS if just the CSS doesn't fix it. 另外我可能是错的,你可能不需要做DIV所以先试试CSS然后尝试DIV和CSS,如果只是CSS没有修复它。 Hope this helps you. 希望这对你有所帮助。

CSS is ( over ) compensating for your ( hidden ) 45px tall header bar! CSS(过度)补偿你的(隐藏的)45px高标题栏!

All you need to do is bravely & mysteriously use bottom: 45px and not bottom: 0px in your CSS: 所有你需要做的是勇敢和神秘地使用bottom: 45px不是 bottom: 0px你的CSS中的bottom: 0px

.fixed{
    position: fixed;
    top: 0px;
    bottom: 45px;
}

I have your demo interface working perfectly if I open my Element Inspector and change only the above. 如果我打开Element Inspector并仅更改上面的内容,我的演示界面就能完美运行。

Using percentage based heights is not an exact fix for you ( or anyone ). 使用基于百分比的高度并不是您(或任何人)的精确修复。 There will be gaps that way. 这样会有差距。

Start by taking the min-height: 1000px off #sidebar . 首先采用min-height: 1000px关闭#sidebar Then choose your poison below for .innerscroll . 然后在下面为.innerscroll选择你的毒药。

It's hiding the button at the bottom because .cat-select has a height of 22px. 它隐藏了底部的按钮,因为.cat-select的高度为22px。 Setting height: 100% sets .innerscroll to the height of the parent, no matter what other children are in the parent div. 设置height: 100%.innerscroll设置.innerscroll的高度,无论父级div中的其他子级是什么。 So if the parent is 500px, .innerscroll will also be 500px, just bumped down by 22px. 因此,如果父母是500px, .innerscroll也将是500px,刚刚减少22px。 Bumping it down causes this 22px to be hidden at the bottom of the div. 将其降低使得22px隐藏在div的底部。 You can see this by setting position: absolute; top: 0 您可以通过设置position: absolute; top: 0 position: absolute; top: 0 on .innerscroll . position: absolute; top: 0 on .innerscroll

Three options (number three being my personal choice): DEMO 三个选项(第三个是我个人的选择): DEMO

  1. You can use height: calc(100% - 22px) if calc works for your implementation (caniuse.com). 如果calc适用于您的实现(caniuse.com),您可以使用height: calc(100% - 22px) )。

  2. Or you can shrink .innerscroll as has been specified in other answers ( height: 98% or whatever works for your case). 或者您可以缩小.innerscroll如其他答案中所指定的那样( height: 98%或适用于您的情况)。

  3. Or you can set position: absolute; top: 0; 或者你可以设置position: absolute; top: 0; position: absolute; top: 0; to .innerscroll , then set margin-top: 22px on .listing . .innerscroll ,然后设置margin-top: 22px on .listing This will set the scrolling div with overflow-y to match top and bottom of the parent, and cause the 22px push down inside that div. 这将设置具有overflow-y的滚动div以匹配父级的顶部和底部,并使22px向下推入该div内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM