【问题标题】:how to change some css Properties according to text length如何根据文本长度更改一些 css 属性
【发布时间】:2014-06-02 21:40:28
【问题描述】:

所以我正在处理 wordpress 列表帖子循环,我在 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/

这可能吗?以及如何?

【问题讨论】:

    标签: css wordpress font-size


    【解决方案1】:

    有一个 jquery 插件......你可以使用它..它的灵活..使用这个 fittextjs

    【讨论】:

      【解决方案2】:

      现在定义

      .container{
      line-height:25px; // add this line 
      height:25px;  // remove this line
      }
      

      Demo

      【讨论】:

      • 我希望高度是固定的,字体大小和行高都是动态的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      • 1970-01-01
      • 2014-05-14
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      相关资源
      最近更新 更多