2013-03-21 81 views
1

希望你能帮助我解决我的问题。作出abosolute位置div伸展内容宽度

我有一个div绝对定位(这是不能改变的)。这个div有最大和最小宽度。

想要我想实现的是div伸展到它的内容并且只有当它超过宽度时才从一条新线开始。

HTML:

<div class="black_tooltip_container "> 
    some text in here, it can be anything! 
</div> 

CSS:

position:absolute; min-width:10px; max-width:150px; 

我看到:

_____________ 
    | some  | 
    | text  | 
    | in  | 
    | here,  | 
    | it  | 
    | can  | 
    | be  | 
    | anything! | 
    _____________ 

我希望看到的:

  width: 150px 
    _______________________________ 
    | some text in here, it can | 
    | be anything!    | 
    ______________________________ 

编辑: 问题解决。问题是,我没有意识到div被嵌套在一个相对位置和宽度为div的div中:50px;

从它的父取出后,担任spected

+1

它的工作如预期http://jsfiddle.net/dV2Bm/ – Sachin 2013-03-21 21:50:48

回答

1

你应该工作什么:

<div class="black_tooltip_container "> 
    some text in here, it can be anything! 
</div> 

.black_tooltip_container { 
    border:1px solid; 
    min-width:10px; 
    max-width:150px; 
    position:absolute; 
} 

见这里:

http://jsfiddle.net/nbHMY/

+0

oops,jsfiddle网址不正确.. – kinopyo 2013-11-29 08:13:50

+0

修复了小提琴网址。 – 2013-12-02 16:02:24