可以maxHeight在父级上设置并让一个特定的孩子 (1) 占用尽可能多的空间并且 (2) 已经overflow-y: scroll在那个孩子上设置了吗?
<div style="max-height: 200px">
<div>Header that I don't want to specify any height on</div>
<div style="max-height: auto; overflow-y: scroll">
<div>Item no 1 in long list>
<div>Item no 2 in long list>
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
上面的代码并max-height: auto不起作用。我最接近的是只有一个孩子并将其设置max-height为inherit这样:
<div style="max-height: 200px">
<div style="max-height: inherit; overflow-y: scroll">
<div>Item no 1 in long list>
<div>Item no 2 in long list>
...
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
哪个有效,但如果我有 2 个孩子并且max-height: …
css ×1