Search code examples
csshtmlfixed

Div should remain fixed only in specific div


Sorry if my tune is not good! I am using this HTML code

HTML:

<div style="width:300px; height:300px; background-color:blue; overflow:scroll">
   <div style="width:100px; height:100px; background-color:red; position:fixed"></div>
</div>

CSS:

  .outer {
    width:200px;
    height:600px;
    background-color:red;
    margin:0 auto;
}
.inner {
    width:50px;
    border:1px solid white;
    position:fixed; margin-left:150px
}

Question: My question is this, The inner div should remain fixed just within outer div. When I scroll page down inner div should remain fixed, but when outer div end and page goes to next div, the fixed div should also move with outer div. It should not remain fixed in other div's.


Solution

  • you have not closed the outer div element.