CSS: sidebar with fixed position getting cut off

限于喜欢 提交于 2019-12-05 08:17:30

You could do a test in javascript. Either in pure javascript, or with jQuery (would be a lot easier).

Here's an example for jQuery :

$(window).resize(function() {
  if ( $(window).height() < 800) {
    $('#Sidebar').addClass('beAbsolute').removeClass('beFixed');
  } else {
    $('#Sidebar').addClass('beFixed').removeClass('beAbsolute');
  }
});

CSS :

.beFixed {position:fixed;}
.beAbsolute {position:absolute;top:0px;}

By default, use the absolute version, so that user without JavaScript can see the whole sidebar.

Try overflow-y:auto and cap the size. I recommend capping it as something smaller than 1020 pixels, because a lot of people are running on smaller screens (my 15" laptop, for example, is 1366x768, so I'd only be able to see about 3/4) and even those on larger screens don't necessarily maximize their windows. Untested, but height:100% might/should work.

It will add a scroll bar to the div itself, so make sure to account for that, but it will make the div scrollable, which will solve your problem. It does sacrifice a little usability (scrollbars other than the main window ones are generally frowned upon), though.

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