font-size取决于字符长度? [英] font-size depending on character length?

查看:199
本文介绍了font-size取决于字符长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以根据div的字体大小更改div的字体大小?我有图片专辑标题在小固定宽度div(100像素)。有时,相册名称有太多的字符,他们强制换行。所以我想知道是否可以重新调整字体大小以保持标题在一行上。

Is it possible to change the div's font-size depending on how many characters are in it? I have image album titles in small fixed width div's (100px). Sometimes the album names have too many characters that they force a new line. So I was wondering if it is possible to re-size the font to keep the title on one line?

推荐答案

是的,为类指定一个变量:

Yes, by assigning a variable to a class:

在您的css中:

.longstring {
  font-size: 10pt;
}
.shortstring {
  font-size: 14pt;
}

在您的视图中

<?php
$random_number = '42';
if(strlen($div_string)>$random_number){
    $font_class = 'longstring';
}else{
    $font_class = 'shortstring';
}?>
<div class="<?php echo $font_class; ?>">
    <?php echo $div_string; ?>
</div>

这篇关于font-size取决于字符长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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