This question already has an answer here:
这个问题在这里已有答案:
- Font scaling based on width of container 30 answers
- HTML / CSS - adjust font-size to fill parent height and width 5 answers
基于容器30的宽度的字体缩放答案
HTML / CSS - 调整字体大小以填充父高度和宽度5答案
I have a fixed size <header>
(let's say 300px in width by 200px in height) and a text inside. Here's my structure:
我有一个固定大小的
Header 1:
<header>
<h1>
This is example title, but the text length might be different.
</h1>
</header>
I have multiple headers just like this, but with various text length, example:
我有这样的多个标题,但有不同的文本长度,例如:
Header 2:
<header>
<h1>
This is small-length text.
</h1>
</header>
Header 3:
<header>
<h1>
This is bigger-length text. This is example title, but the text length might be different.
</h1>
</header>
I want scale the text font-size in this fixed-size <header>
as much as possible (without exceeding the <header>
bounds, in width and height). And I want to do it dynamically, so it matches any text length. Do you have any ideas how I can do that?
我希望尽可能在这个固定大小的
PS: Here's a JS fiddle that illustrates the problem: https://jsfiddle.net/superKalo/nqf46tft/
PS:这是一个说明问题的JS小提琴:https://jsfiddle.net/superKalo/nqf46tft/
Edit: I assume a CSS only solution is not possible. Do you know any javascript trick that would solve this problem?
编辑:我认为不可能只有CSS解决方案。你知道任何可以解决这个问题的javascript技巧吗?
1 个解决方案
#1
0
Check this out. But, i think you need to do a lot of work. http://madebymike.com.au/writing/precise-control-responsive-typography/
看一下这个。但是,我认为你需要做很多工作。 http://madebymike.com.au/writing/precise-control-responsive-typography/
#1
0
Check this out. But, i think you need to do a lot of work. http://madebymike.com.au/writing/precise-control-responsive-typography/
看一下这个。但是,我认为你需要做很多工作。 http://madebymike.com.au/writing/precise-control-responsive-typography/