我正在使用 flexbox 布局,并试图让特定 div 中的文本调整大小以适合该 div。
例如,如果我有如下代码:
<div style={{display: "flex"}}>
<div style={{flex: 1}}>
A really, really, really, really long phrase here that will fit this div, and may wrap onto multiple lines if necessary. In this case it should fill half of the available space as the other div will cover the other half of the space.
</div>
<div style={{flex: 1}}>
Some other text
</div>
</div>
实际上,文本将从数据库中提取,因此长度是动态的。
如何让第一个 div 中的文本自动调整以适合整个 div?
澄清: div 应该保持固定大小,只有文本应该缩小以适应 div 而不是溢出 div。
更新
我还发布了一个更具体的问题,关于一个名为react-textfit的特定module没有按照我期望的方式工作。