是否可以使用 CSS 将字体大小调整为 div 宽度? [英] Is it possible to adapt font size to div width with CSS?

查看:18
本文介绍了是否可以使用 CSS 将字体大小调整为 div 宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 70% 宽度的 div,这是我想要做的:

  • 在那个 div 中放一些词
  • 调整字体大小,使那些词占据所有 div 宽度

<小时>

这可以仅用 css 吗?这是我的代码:

.parent {宽度:70%;高度:自动;最小高度:100px;背景:红色;字体大小:10vw;}

请帮我动态更改字体大小到父类<小时><div class="parent">本文

<块引用>

注意:div 大小是响应式的,这很重要.感谢前进!<​​/p>

解决方案

你只需要在你的代码中添加 display: inline;

.parent {宽度:70%;高度:自动;最小高度:100px;背景:红色;字体大小:10vw;显示:内联;}

本文

I have a div with 70% width, and here’s what I want to do:

  • Put some words in that div
  • Adapt font size so that those words occupy all div width


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>

Note: the div size is responsive, this is important. Thanks in advance!

解决方案

You just have to add display: inline; in your code

.parent {
  width: 70%;
  height: auto;
  min-height: 100px;
  background: red;
  font-size: 10vw;
  display: inline;
}

<div class="parent">
  This Text
</div>

这篇关于是否可以使用 CSS 将字体大小调整为 div 宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆