I want to position my button on the bottom of a div or the bottom of the screen (but in a non-fixed position). My code structure looks like this:
- div-1
- div-2
- div-3
- button
- div-3
- div-2
I want to put the button at the bottom of div 1, which height is set using jQuery (The height is the height of the screen, so putting the button at the bottom of the screen may also be a solution)
What I've tried so far:
CSS
.button {
position: fixed;
bottom: 10px;
left: 50%;
margin-left: -104.5px; /*104.5px is half of the button's width*/
}
This centers the button (what I want) and it places it at the bottom of the screen, but the position is fixed, so if I scroll down the button goes down aswell.
I've also tried setting the button's position
to absolute
and div-1's position
to relative
, this didn't work either.
Edit: The div's height is variable, so margins may not be such a good option