Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button at the center and bottom of div

Tags:

html

css

button

How to make a button be at the bottom of div and at the center of it at the same time?

.Center {
  width: 200px;
  height: 200px;
  background: #0088cc;
  margin: auto;
  padding: 2%;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}

.btn-bot {
  position: absolute;
  bottom: 0px;
}
<div class=Center align='center'>
  <button class='btn-bot'>Bottom button</button>
</div>
like image 563
nuT707 Avatar asked Mar 04 '14 03:03

nuT707


People also ask

How do you center a button at the bottom of a div?

Wrap the button in a parent <div> and set the parent to display: flex and justify-content: center .

How do you move a button to the bottom of the center in CSS?

We can center the button by using the following methods: text-align: center - By setting the value of text-align property of parent div tag to the center. margin: auto - By setting the value of margin property to auto.


2 Answers

Give the parent element…

display: table; text-align: center;

…and its child element…

display: table-cell; vertical-align: bottom;

This way you do not need to know the width of the child element in case it changes, thus requiring no negative margins or workarounds.

like image 169
cdcdcd Avatar answered Oct 08 '22 03:10

cdcdcd


For example write like this if you have position absolute:

.btn-bot{
   position:absolute; 
   margin-left:-50px;
   left:50%;
   width:100px;
   bottom:0px;
}

Note: give margin-left half of the width of the button.

JSFiddle demo

like image 39
Chankey Pathak Avatar answered Oct 08 '22 04:10

Chankey Pathak