首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >css固定和绝对问题

css固定和绝对问题
EN

Stack Overflow用户
提问于 2016-06-22 16:34:22
回答 3查看 65关注 0票数 0

我的页面中有3个元素。它们分别是外部、中间和内部。

html代码:

代码语言:javascript
复制
<div class="outer">
  <div class="middle">

      <div class="inner">
        inner suppose to stay at the bottom of the outer.
       </div>
  </div>
</div>

css代码:

代码语言:javascript
复制
.outer {
  position: fixed;
  top: 20px;
  max-width: 400px;
  background: red;
  height: 400px;
  overflow: auto;
  width: 200px;
}
.middle {
  width: 100%;
  height: 800px;
  padding: 100px 0;
  position: static;
  background: green;
}
.inner {
  width: 100%;
  position: absolute;
  height:100px;
  background: yellow;
  bottom: 0
}

我认为内部应该留在外部的底部。然而,我没有。有人能告诉我为什么吗?

EN

Stack Overflow用户

发布于 2016-06-22 17:13:50

我已经做到了这一点,问题是内部的宽度,不能使用100%,因为重叠滚动条。我的设置是184px,在我的电脑上使用Chrome和Firefox运行得很好,但可能在其他浏览器或其他浏览器上并不是最好的:

代码语言:javascript
复制
.dummy {
  position: relative;
  width: 200px;
}

.outer {
  max-width: 400px;
  background: red;
  height: 300px;
  overflow: auto;
  width: 200px;
}

.middle {
  width: 100%;
  height: 800px;
  padding: 100px 0;
  background: green;
}

.inner {
  width: 184px;
  position: absolute;
  height: 100px;
  background: yellow;
  bottom: 0;
}
代码语言:javascript
复制
<div class="dummy">
  <div class="outer">
    <div class="middle">
      <div class="inner">
        inner suppose to stay at the bottom of the outer.
      </div>
    </div>
  </div>
</div>

票数 0
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37962658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档