【问题标题】:How to fix div only inside my another div?如何仅在我的另一个 div 中修复 div?
【发布时间】:2020-06-16 06:05:47
【问题描述】:

**仅用另一个 div 修复 **

这是我使用的代码... HTML 代码,

   <div class="container">
        <div class="fix">
            Here fixed content
        </div>
   </div>

CSS 代码,

.container{
    display:flexbox;
    height: 40em;
    background-color: black;
}
.fix{
    position: fixed;
    width: 25em;
    height: 30em;
    background-color: beige;
}

【问题讨论】:

标签: javascript html css web web-site-project


【解决方案1】:

使元素的父容器有位置:relative

<div class="parent">
  <div class="child"></div>
</div>

.parent {
  position: relative;
}
.child {
  position: fixed;
  margin-top: 30px;
  margin-left: 30px;
}

【讨论】:

    【解决方案2】:

    @大师 固定页面上的工作地球。 如果你想在“容器”中工作,你应该使用 position:sticky 而不是 fixed

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-10-08
      • 1970-01-01
      • 2013-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多