Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center image in table td in CSS

Tags:

html

css

I've been trying to align an image to the center of the table td. It worked with setting margin-left to a specific value but it also increased the size of td too and that isn't exactly what I wanted

Is there any efficient ways of doing this? I used percentages for the height and witdh of the table.

like image 316
Best Avatar asked Dec 22 '11 12:12

Best


People also ask

How do I center an image in a table CSS?

To center an image with CSS Grid, wrap the image in a container div element and give it a display of grid . Then set the place-items property to center. P.S.: place-items with a value of center centers anything horizontally and vertically.

How do I center align an image in CSS?

To center an image, we have to set the value of margin-left and margin-right to auto and make it a block element by using the display: block; property. If the image is in the div element, then we can use the text-align: center; property for aligning the image to center in the div.

How do I center a TD in CSS?

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.


1 Answers

<td align="center"> 

or via css, which is the preferred method any more...

<td style="text-align: center;"> 
like image 169
Scott Avatar answered Sep 28 '22 05:09

Scott