【问题标题】:make an abosolute position div stretch content width使绝对位置 div 拉伸内容宽度
【发布时间】:2023-03-11 05:42:01
【问题描述】:

希望你能帮我解决我的问题。

我有一个绝对定位的 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 嵌套在一个相对位置和宽度为 50px 的 div 中很远;

将其从其父级中删除后,它按预期工作

【问题讨论】:

标签: css position css-position


【解决方案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/

【讨论】:

  • 修复了小提琴的网址。
猜你喜欢
  • 1970-01-01
  • 2012-03-21
  • 2020-02-24
  • 1970-01-01
  • 1970-01-01
  • 2012-05-26
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多