HTML / CSS - 调整字体大小以填充父级高度和宽度
我有一个
元素,它会随着浏览器窗口大小的调整而调整大小。在
内,我有一段文本:<div style="width:80%; height:80%; margin:10%;">
<p>Paragraph of text. Paragraph of text. Paragraph of text.</p>
</div>
我希望文本在调整
大小时更改 font-size
。
,这样文本就会占据 100% 的可用空间。我怎样才能达到这个效果?
是用百分比字体大小吗?
我必须使用 Javascript 吗?
提前致谢!
I have a <div>
element that resizes as the browser window resizes.
Inside the <div>
I have a paragraph of text:
<div style="width:80%; height:80%; margin:10%;">
<p>Paragraph of text. Paragraph of text. Paragraph of text.</p>
</div>
I want the text to change font-size
as I resize the <div>
, so that the text will occuypy 100% of the available space.
How can I achieve this effect?
Would it be with a percentage font-size?
Would I have to use Javascript?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
有一个 jquery 插件:http://fittextjs.com/
There's a jquery plugin for this: http://fittextjs.com/
HTML
CSS
JavaScript
HTML
CSS
JAVASCRIPT
fittext.js
对我来说不能正常工作(jQuery 插件,以及派生的无 jquery 版本),也不能使用压缩器属性,所以我找到了另一个解决方案:http://www.dhtmlgoodies.com/?whichScript=text_fit_in_box
(某人的另一部作品)
对我来说非常适合 - 较长的文本以及较短的文本。
它只是不会对窗口大小的调整做出反应(它在加载页面时只工作一次),因此我编写了这段简短的代码,以便在每次调整窗口大小后自动运行它(它对我有用):
我希望它可以对某人有所帮助。
fittext.js
did not work correctly for me (plugin for jQuery, as well as derived jquery-free version), nor with using of compressor attribute, so I found another solution:http://www.dhtmlgoodies.com/?whichScript=text_fit_in_box
(someone's another work)
which works perfectly for me - longer texts as well as shorter texts.
It just do not react to resize of window (it works just once on loading of page), so I have written this short code to run it automatically after each window resize (it works for me):
I hope it can help to someone.
查看 css 中的 vw 属性
http://www.w3schools.com/cssref/css_units.asp< /a>
Check out the vw properties in css
http://www.w3schools.com/cssref/css_units.asp