没有固定高度的滚动条带有滚动条的动态高度

没有固定高度的滚动条带有滚动条的动态高度,第1张

没有固定高度的滚动条/带有滚动条的动态高度

Flexbox是一种现代替代方案,可让您无需固定高度或Javascript即可执行此 *** 作。

设置

display: flex; flex-direction: column;
在容器上,并
flex-shrink:0;
页眉和页脚的div的伎俩:

HTML:

<div id="body">    <div id="head">        <p>Dynamic size without scrollbar</p>        <p>Dynamic size without scrollbar</p>        <p>Dynamic size without scrollbar</p>      </div>    <div id="content">        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>        <p>Dynamic size with scrollbar</p>    </div>    <div id="foot">        <p>Fixed size without scrollbar</p>        <p>Fixed size without scrollbar</p>    </div>  </div>

CSS:

#body {    position: absolute;    top: 150px;    left: 150px;    height: 300px;    width: 500px;    border: black dashed 2px;    display: flex;    flex-direction: column;}#head {    border: green solid 1px;    flex-shrink: 0;}#content{    border: red solid 1px;    overflow-y: auto;    }#foot {    border: blue solid 1px;    height: 50px;    flex-shrink: 0;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5621444.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存