所以我正在处理wordpress list posts循环,并且我在div中放置了具有固定宽度和高度的帖子标题。
但是有些帖子标题很长,所以我希望它的字体较小,行高较小,但是我不能为此改个新类,

这是我的意思:

<div class="post-title">hellow hellow hellow</div>
<div class="post-title-2">hellow hellow hellow hellow hellow</div>
<style>
.post-title{
width: 100px; height: 25px;
border:1px #000 solid;
font-size: 14px;
}
.post-title-2{
width: 100px; height: 25px;
border:1px #000 solid;
line-height:100%;
font-size: 11px;
}
</style>


在JSFiddle中:

http://jsfiddle.net/wLh3K/3/

那可能吗?如何?

最佳答案

有一个jquery插件...您可以使用..它灵活..使用它
fittextjs

关于css - 如何根据文本长度更改某些CSS属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23153102/

10-13 01:07