我有一个 div 定位固定在网页的左边,包含菜单和导航链接。它没有从css设置的高度,内容决定高度,宽度是固定的。问题是如果内容太多, div 将大于窗口的高度,并且部分内容将不可见。 (滚动窗口没有帮助,因为位置固定和 div 不会滚动。)
I have a div positioned fixed on the left side of a web page, containing menu and navigation links. It has no height set from css, the content determines the height, the width is fixed. The problem is that if the content is too much, the div will be larger than the window's height, and part of the content will not be visible. (Scrolling the window doesn't help, since the position is fixed and the div won't scroll.)
我试图设置 overflow-y:auto; 但是这没有帮助,div不似乎注意到它的一部分是在窗口之外。
I tried to set overflow-y:auto; but that doesn't help either, the div doesn't seem to notice that part of it is outside of the window.
如果需要,如何使它的内容可滚动,如果 div 挂起的窗口?
How can I make it's contents scrollable only, if needed, if the div hangs out of the window?
推荐答案你可能不能。这里是接近的东西。如果下面有空格,您将不会收到内容。
You probably can't. Here's something that comes close. You won't get content to flow around it if there's space below.
jsfiddle/ThnLk/3
.stuck { position: fixed; top: 10px; left: 10px; bottom: 10px; width: 180px; overflow-y: auto; }更新:您也可以做一个百分比高度:
Update: You can do a percentage height as well:
jsfiddle/ThnLk/6
.stuck { max-height: 100%; }更多推荐
固定位置div可滚动
发布评论