Reputation: 12729
I made a simple demo in which I have a div containing a button, but the button is not vertically aligned I used line-height as well as position absolute and top margin but it does not work. Why doesn't it work? Here is my code:
<div ng-app='app'>
<div ng-controller='first as f'>
<div class='col-xs-4 text-center' style='background-color:red;height:70px;line-height:70px'>
<button type="button" class="btn btn-primary btn-lg btn-block" style:'position:absolute;top:10px'>Block level button</button>
</div>
</div>
</div>
http://codepen.io/naveennsit/pen/KVawpW
Upvotes: 1
Views: 1741
Reputation: 977
You are using CSS incorrectly style:'position:absolute;top:10px
.
it should be.
<button type="button" class="btn btn-primary btn-lg btn-block" style='position:absolute;top:10px'>Block level button</button>
or you can use this code this will also work fine.
<button type="button" class="btn btn-primary btn-lg btn-block" style='margin-top:10px;'>Block level button</button>
here is codepan which I've edited click here
Upvotes: 0
Reputation: 19341
Use following css. Make button position absolute and div position relative.
.btn-block {
left: 50%;
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
.col-xs-4 text-center{
position:relative;
}
Note: If possible try to avoid inline css.
Upvotes: 1