Reputation: 3688
My code goes like this,
<div class="container">
<div class="button"></div>
</div>
.container { position: relative; }
.button { position: fixed; top: 0; right: 0; }
This is a responsive page and width of the container is dynamically changing when re-sizing the window. I want to stick the .button
inside the container at top right side even the page is scrolling. But my code shows the .button
outside the .container
at top right of the screen.
Please help me fix this.
Thanks and Regards.
Upvotes: 3
Views: 7995
Reputation: 6110
You should use position: absolute
for this.
.container { position: relative; }
.button { position: absolute; top: 0; right: 0; }
position: fixed
is positioned against the window, not the parent.
Upvotes: 6
Reputation: 4237
From what I know position:fixed;
is relative to main window, not to parennt.
Upvotes: 0