Pin a button to the bottom of a form using absolute position
Use absolute position to pin elements in a specific place inside the boundaries of a relative parent element.
Absolute-position a submit button so that it’s pinned to the bottom of a form
To do that, first, we need to relatively position the form element. Because, If we absolute-position the submit button first, the button may jump to an unexpected location. So, to keep the button inside the form element, let’s set the form element’s position to relative:
- Select the form element
- Set its position to relative
And now, let’s position the button:
- Select the submit button inside the form
- Set the position to absolute
- Set the bottom, left and right values to 0px
- Set the width: 100%
You may notice the submit button might overlap other form elements now that it’s absolute positioned. If this happens, you can fix it by adding bottom padding on the form element to compensate for the submit button’s height.