Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to override td align="center"?

As gathered from Why align="center" not overriding on {text-align:right;} this article, CSS should take prescience over old-style layout attributes. I am working on a project where I have to inject content in a cell that has the format:

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

I do not want my content to be centered, trying to use text-align="left" does not override the td-tag, as suggested in the article. What can I do to override the TD align attibute?

like image 594
bjornl Avatar asked Aug 16 '10 08:08

bjornl


1 Answers

If you are allowed to change the content of the td, you can then wrap the td values with another tag with text-align:left;

Resulting Tag would be:

<td align="center">
  <div class="left">content here</div>
</td>

Here is the new CSS:

td div.left { text-align:left; }

If you cannot modify the cell value, another work around is to modify the align attribute using javascript, In jquery:

$(document).ready(function(){
   $('td [align=center]').attr('align','left');
   // $('td [align=center]').attr('align','left').css('text-align','left'); //or still not working
});
like image 169
jerjer Avatar answered Oct 05 '22 06:10

jerjer