Home » Angularjs » Trying to center align button in td

Trying to center align button in td

Posted by: admin November 30, 2017 Leave a comment

Questions:

I’m having trouble centering a button in a td.

This is probably a simple CSS issue, but the app is using bootstrap, AngularJS, AngularJS-ui-bootstrap, and ngTable. I’ve included all of these components in my plunkr.

I’m trying to set “horizontal-align: middle” on the td with the button, but that doesn’t seem to get applied. The button still leans to the left side of the cell.

Answers:

You can use :

display: block;
margin: auto;

Here is your updated plunkr

Questions:
Answers:

As I said in my comment above simply change the TD to have the align=”center” property.

<td align="center"></td>

Since posting this I’ve discovered that this is deprecated in HTML5 so best just to use “text-align: center” on the TD in your CSS>

Questions:
Answers:

Alter the button instead of td? Make less impact on the style.

table .btn{
  vertical-align: top;
}

Questions:
Answers:

This worked for me

<td style="text-align: center">

Questions:
Answers:

I found that I had to combine the following attributes to center JSF controls on a page:

<h:form style="display: block; text-align: center; margin: auto; width: 200px">
<!-- components here -->
</h:form>