【问题标题】:How to make child of absolute positioned parent to expand its width?如何使绝对定位父级的子级扩展其宽度?
【发布时间】:2015-04-07 12:22:28
【问题描述】:

关于这个问题有很多相同的问题,但我想我有不同的情况。

好的,我有一个带有position: fixed 的块,具有指定的宽度,并且里面有绝对定位的块。我想让这个工具提示足够灵活,以包含大量文本(最多 2-3 行)或仅包含几个单词。但不超过 400 像素。

我在这里尝试了很多属性,但都没有运气。也许你知道这样做很热?

这是理解样式所需的所有代码:codepen.io/Grawl/pen/EazNJJ

简而言之:

.fixed {
  position: fixed;
  top: 34%;
  right: 0;
  width: 36px;
}
.absolute {
  position: absolute;
  top: 0;
  right: 100%;
}
.absolute p {
  /* what have I do here? */
}
<div class="fixed">
  <div class="absolute">
    <p>How to make this block parent have this block width?</p>
  </div>
</div>

【问题讨论】:

  • 你的问题不清楚

标签: html css width absolute


【解决方案1】:

一种解决方案是将这个绝对 div 包装在相对定位的 div 中。这样可以更好地控制元素。

【讨论】:

    猜你喜欢
    • 2013-12-30
    • 1970-01-01
    • 2010-11-16
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多