How to make button be at the bottom of div and at the center of it at the same time?
Here's my code: http://jsfiddle.net/3QguR/1/
HTML
<div class='Center' align='center'>
<button class='btn-bot'>button-bottom</button>
</div>
CSS
.Center{
width:200px;
height:200px;
background:#0088cc;
margin:auto;
padding:0%;
position: relative;
top: 0; left: 0; bottom: 0; right: 0;
border-radius:5%;
}
.btn-bot{
position: absolute;
bottom: 0;
}
For example write like this if you have position absolute:
Note: give margin-left half of the width of the button.
JSFiddle demo
I used
table-row
to combine text and button in one container:CodePen
One way of doing this would be to give it an absolute width and then a margin half of that:
Another way would be to give the
div
the following line-height and remove all styles from thebutton
:Give the parent element…
…and its child element…
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.
Does the button need to be absolutely positioned? If so, you could specify a width and then a negative left margin:
fiddle
This is what worked for me and I think is what several people were trying to get at. Just use a full width wrapper div with the button centered inside it.
Result:
Fiddle