字体大小等于当前容器的高度
如果我有一个 x 高的 div,我怎样才能使它里面的文本最大,假设它只能占用一行。
虽然我更喜欢 CSS 答案,但任何 jquery/javascript 答案都会被接受,因为我需要它以任何方式工作:)
If I have a div that is x high, how can I make the text inside of it the max it can be assuming that it can only take up one line.
While I would prefer a CSS answer, any jquery/javascript answers are accepted just because I need this to work either way :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Aleks G 的评论,此示例展示了如何逐渐增加字体大小,直到达到最大值:
HTML
CSS
jQuery
如果您想消除字体大小更改时的任何卡顿,您可以隐藏文本,直到
while
循环已完成。Based on Aleks G's comment, this example shows how you would incrementally increase the font size until you'd reached your max:
HTML
CSS
jQuery
If you wanted to eliminate any stuttering as the font size was being changed, you could hide the text until the
while
loop was complete.将 font-size 和 line-height 设置为容器的相同高度:
演示: http://jsfiddle.net /AlienWebguy/V7f4w/
Set the font-size and line-height to the same height of the container:
Demo: http://jsfiddle.net/AlienWebguy/V7f4w/
我不知道如何使用跨浏览器兼容的纯 CSS 来做到这一点。使用 javascript 和/或 jquery 来执行此操作。我会用 jquery 写出来,因为它更容易一些:
No way I know of to do that with pure CSS that will be cross browser compatibile. Use javascript and/or jquery to do this. I'll write it out in jquery since its a bit easier: