html - 如何将 div 扩展到某个高度,并且仅在该滚动之后?
问题描述
我有一个最初是一定大小的 div,比如 100px。我希望它能够扩展以适应内容,比如直到 250 像素,然后滚动。我试过使用
text-overflow: ellipsis; max-height: 250px; overflow-y: scroll;
但它不起作用,一旦文本溢出 100 像素,它就会滚动。
我怎样才能只使用 css 来做到这一点?
解决方案
根据 Ajeet Eppakayala 的评论,这似乎可行,将 div 扩展到 250px 高度,然后显示滚动条:
<style>
div {
text-overflow: ellipsis;
font-size:20px;
min-height: 100px;
max-height: 250px;
height:auto;
overflow-y:auto;
background-color:cyan;
margin-top:20px;
}
</style>
<p>height:100px;</p>
<div>
1<br>2<br>3<br>
</div>
<p>height: whatever is required for the text</p>
<div>
1<br>2<br>3<br>1<br>2<br>3<br>4<br>5
</div>
<p>height:250px and scrolling</p>
<div>
1<br>2<br>3<br>1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br>11<br>12<br>12<br>14<br>15<br>16<br>
</div>
推荐阅读
- python - 如何修复 ImportError:没有名为 main 的模块
- excel - 索引匹配未返回正确值
- node.js - 为什么 mongoose 中的 model.find() 在创建集合之前运行?
- python - 熊猫查找列的值计数
- css - 悬停时如何更改行颜色
- node.js - 在 mongoose 中使用 or 和 and 运算符
- modelica - cd 命令在 Dymola.mos 文件中不起作用
- binaryreader - 有没有办法读取存储在二进制(.bin)文件中的信息?
- stargazer - 观星者:F Statistic / df 中的换行符
- typescript - 如何在 TypeScript 中使对象参数的一个属性是必需的,而其余的属性是可选的?