3

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

4

2 回答 2

3

是的,通过将变量分配给类:

在你的 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>
于 2012-01-28T13:04:45.350 回答
1

没有 css 方法可以做到这一点,您可以在 css3中使用 javascript 或text-overflow

于 2012-01-28T13:07:35.460 回答