Align button at the bottom of div using CSS

CssButtonAlignment

Css Problem Overview


I want to align my button at the bottom right corner of my div. How can I do that?

enter image description here

Current css of div:

    float: right;
	width: 83%;
	margin-right: 0px;
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
	height:625px;
	overflow:auto;

Css Solutions


Solution 1 - Css

You can use position:absolute; to absolutely position an element within a parent div. When using position:absolute; the element will be positioned absolutely from the first positioned parent div, if it can't find one it will position absolutely from the window so you will need to make sure the content div is positioned.

To make the content div positioned, all position values that aren't static will work, but relative is the easiest since it doesn't change the divs positioning by itself.

So add position:relative; to the content div, remove the float from the button and add the following css to the button:

position: absolute;
right:    0;
bottom:   0;

Solution 2 - Css

CSS3 flexbox can also be used to align button at the bottom of parent element.

Required HTML:

<div class="container">
  <div class="btn-holder">
    <button type="button">Click</button>
  </div>
</div>

Necessary CSS:

.container {
  justify-content: space-between;
  flex-direction: column;
  height: 100vh;
  display: flex;
}
.container .btn-holder {
  justify-content: flex-end;
  display: flex;
}

Screenshot:

Output Image

Useful Resources:

* {box-sizing: border-box;}
body {
  background: linear-gradient(orange, yellow);
  font: 14px/18px Arial, sans-serif;
  margin: 0;
}
.container {
  justify-content: space-between;
  flex-direction: column;
  height: 100vh;
  display: flex;
  padding: 10px;
}
.container .btn-holder {
  justify-content: flex-end;
  display: flex;
}
.container .btn-holder button {
  padding: 10px 25px;
  background: blue;
  font-size: 16px;
  border: none;
  color: #fff;
}

<div class="container">
  <p>Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... Lorem ip sum dolor sit amet... </p>
  <div class="btn-holder">
    <button type="button">Click</button>
  </div>
</div>

Solution 3 - Css

Parent container has to have this:

position: relative;

Button itself has to have this:

position: relative;
bottom: 20px;
right: 20px;

or whatever you like

Solution 4 - Css

I have solved this using position fixed:

.button-corner {
  position: fixed;
  bottom: 20px;
  right: 20px;
}

Solution 5 - Css

Goes to the right and can be used the same way for the left

.yourComponent
{
   float: right;
   bottom: 0;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarry JoyView Question on Stackoverflow
Solution 1 - CssKokosView Answer on Stackoverflow
Solution 2 - CssMohammad UsmanView Answer on Stackoverflow
Solution 3 - CssAronView Answer on Stackoverflow
Solution 4 - CssLeandro Hernández MiraView Answer on Stackoverflow
Solution 5 - CssBehranG BinAView Answer on Stackoverflow