I have a div container with a responsive width and height when I start minimizing the page. It also has a min-width. I want add a floating action button that is 24px from the bottom and 24px from the right of the div container. I’ve tried making the container’s position relative, while the button will have a position of fixed, but the button is still relative to the viewport.
Is what I’m trying to accomplish even possible with fixed position?
Is there another way to do this, or possibly recalculate the position of the button based on the containers width?
<div class="container">
<button class="button" type="button">
I want to be relative to my container and not the viewport
</button>
</div>
.container {
position: relative;
min-height:500px;
min-width: 1500px;
}
.button {
position: fixed;
bottom: 24px;
right: 24px;
}
2
Answers
Why not
position: absolute
on the button?For the desired effect, you should use
position: absolute
instead ofposition: fixed
.