0

**Fix only with another div **

Here is the code that I used... HTML code,

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

CSS code,

.container{
    display:flexbox;
    height: 40em;
    background-color: black;
}
.fix{
    position: fixed;
    width: 25em;
    height: 30em;
    background-color: beige;
}
  • [https://stackoverflow.com/questions/6794000/fixed-position-but-relative-to-container](https://stackoverflow.com/questions/6794000/fixed-position-but-relative-to-container) – Sfili_81 Jun 16 '20 at 06:49

2 Answers2

1

Make the element's parent container have position: relative

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

.parent {
  position: relative;
}
.child {
  position: fixed;
  margin-top: 30px;
  margin-left: 30px;
}
Cheris Patel
  • 56
  • 1
  • 4
0

@Guru fixed work globe on page. If you want to work in "container" you should use position:sticky instead fixed

Tien Nguyen
  • 106
  • 6