固定位置div可滚动

编程入门 行业动态 更新时间:2024-10-28 18:24:02
本文介绍了固定位置div可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 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可滚动

本文发布于:2023-10-08 03:14:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471349.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   div

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!