【问题标题】:Flexible, fixed div - Need to stick another div to bottom灵活、固定的 div - 需要将另一个 div 粘贴到底部
【发布时间】:2014-03-15 19:25:31
【问题描述】:

div A 灵活且固定(位于窗口顶部),具有高 z-index,因此下方的项目可以在滚动时从下方通过。

div B 位于 div A 下方,我希望它“粘”在 div A 的底部,因为在调整窗口大小时高度会弯曲。换句话说,让 A 和 B 之间的边距保持一致。

我担心我想多了,解决方案很简单,但我看不到。

HTML

<div id="A">
    some content
</div>

<div id="B">
    some content
</div>

CSS

#A {
position: fixed;
z-index: 200;
width: 100%;
}

#B {
position: relative;
z-index: 100;
width: 100%;
}

【问题讨论】:

  • 你不能把B放进A吗?

标签: html css


【解决方案1】:
a {
  position:fixed;
}

b {
  position:absolute;
  bottom:0;
}

我认为这会起作用,但不知道它与固定而不是相对“a”有何反应

【讨论】:

  • 我无法将 B 设置为底部:0;因为我需要 B 的顶部粘在 A 的底部。
【解决方案2】:

我将 B 放入 A 并执行此操作

http://jsfiddle.net/NicoO/CAF3q/2/

CSS:

#a
{
    position: fixed;
    left:0;
    right:0;
    height: 200px;
    top:0;
    overflow: hidden;
    background-color: gray;
}

#b
{
    overflow: hidden;
    background-color: gold;
    position: absolute;
    bottom:0;
    left:0;
    right:0;

}

HTML:

<div id="a">
    <p>Content of what ever type...</p>
    <p>Content of what ever type...</p>
    <div id="b">
        <p>Everyone is pushing me down 8(</p>
    </div>
</div>

【讨论】:

  • 抱歉,请参阅更新的链接。 div A 不会显示没有我无法设置的指定高度的内容,否则它会破坏灵活的设计。
  • 你没有在你的问题中定义这种行为,最好不要有任何固定的高度,让内容成为它的东西,见上面更新的 url。
  • 也许我错过了一些东西(不足为奇)。我在这个示例中加载了内容以强制滚动并给 A 一些东西以使其垂直调整大小但没有滚动 - jsfiddle.net/CAF3q/8
  • 我想我试图过分简化问题以保持其持续性。
  • 如果你想滚动,你可以设置一个最大高度:jsfiddle.net/NicoO/CAF3q/9 如果这不是你想要的,请准确描述它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 2014-06-15
  • 1970-01-01
  • 2011-10-14
  • 2014-10-01
相关资源
最近更新 更多