Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<th align'"center"> not working on a bootstrap table. What might be the reason?

I have a bootstrap hover table and I'm trying to align the column headers to the middle by using <th align="center">. This seems to have no effect on the table whatsoever, but <td align="center"> works properly.

This is my code:

<table class="table table-hover">     <thead>     <tr>         <th>Title</th>         <th>Score</th>         <th align="center">Product</th>    #This line is not working         <th>Who Reviewed</th>         <th>When</th>     </tr>     </thead>     <tbody>     {% for review in object_list %}         <tr>             <td><a href="{% url 'backend_reviews_edit' review.pk %}">{{review.title}}</a></td>             <td align="center">{{ review.score }}</td>             <td align="center">{{ review.product.title }}</td>             <td>{{ review.reviewer_name}}</td>             <td>{{ review.date_created|date:"m-d-Y" }}</td>         </tr>     {% endfor %}     </tbody> </table>     </div> 
like image 589
DeA Avatar asked Mar 08 '17 22:03

DeA


People also ask

How do I center align a table in bootstrap?

By adding the ” text-center” class of Bootstrap 3 We can use the “text-center” class of bootstrap 3 for the center-alignment of an element. So in our td when we add “text-center” class, and then our table text goes to the center.

How do you center th in a table?

To center align text in table cells, use the CSS property text-align. The <table> tag align attribute was used before, but HTML5 deprecated the attribute. Do not use it. So, use CSS to align text in table cells.

How do I center align th in HTML?

HTML | <th> align Attribute left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align.


1 Answers

If you're using bootstrap, use its CSS rules.

<th class="text-center">Product</th> 
like image 105
Eduardo Escobar Avatar answered Oct 09 '22 16:10

Eduardo Escobar