是否可以使用CSS将字体大小调整为div宽度? [英] Is it possible to adapt font size to div width with CSS?
本文介绍了是否可以使用CSS将字体大小调整为div宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个宽度为70%
的div,这是我想要做的:
I have a div with 70%
width, and here’s what I want to do:
- 在该div中添加一些单词
- 调整字体大小以使这些单词 占据所有div宽度
- Put some words in that div
- Adapt font size so that those words occupy all div width
只有CSS才有可能吗?这是我的代码:
Is this possible with only css? Here is my code:
.parent {
width:70%;
height:auto;
min-height:100px;
background:red;
font-size:10vw;
}
Please help me to change the font-size dynamically to the parent class
<hr>
<div class="parent">
This Text
</div>
请注意:div的大小是自适应的,这一点很重要.谢谢 前进!</p>
Note: the div size is responsive, this is important. Thanks in advance!
推荐答案
也许不是您要找的东西,而是一些东西-您可以使字体和元素都相对于视图宽度.
Perhaps not quite what you're looking for, but something - You can make both the font and the element relative to view width.
p {
font-size: 5vw;
background-color: red;
width: 50vw;
}
<p>
I'm a P!
</p>
这篇关于是否可以使用CSS将字体大小调整为div宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文