如何根据其中字符串的长度修改div的长度?

时间:2015-04-21 03:42:28

标签: javascript jquery css

我尝试根据其中的字符串长度动态拉伸div。怎么办呢?

<div width=magic_function();>
     pickle
</div>

我目前正以聪明的方式使用php strlen来实现这一目标,但我觉得这是一个过程密集型。

<style>
    .tag {
        padding-bottom:2px;
        position:relative;
        background:#BFC9D9;
        margin-right:auto;
        margin-left:auto;
        width:???;
        text-align:center;
        border-top-right-radius:2px;
        border-bottom-right-radius:2px;
        margin-top:3px;
        margin-bottom:3px;
    }
    .tag:after {
        right:100%;
        top:50%;
        border:solid transparent;
        content: " ";
        height:0;
        width:0;
        position:absolute;
        border-right-color:#BFC9D9;
        border-width:10px;
        margin-top:-10px;
    }
</style>

1 个答案:

答案 0 :(得分:1)

试试这个

  .tag {
         display:inline;
         width:auto;
        }
相关问题