mara
mara

Reputation: 1

How do I change the columns widths of this html table

Is there a way to specify column width here?

Hi, I'm trying to style a table, but I don't know how to specify column width. I've read that the way to do it is by using CSS: <td style="width:130px">

I'm using xampp and I only use a PHP file.

<!DOCTYPE html>
<html>

<body>

  <table>
    <tr>
      <td>$item</td>
      <td><img src='item_image_folder/img'></td>
    </tr>
  </table>

</body>

</html>

what the table looks like

Category 1

item_name  image
item_name  image

Category 2

item   image 
item   image 

Category 3

long_item_name   image 

Upvotes: 0

Views: 75

Answers (4)

Jack Bashford
Jack Bashford

Reputation: 44125

Yes, all you'd need to do is select the cell(s) you want to widen, then set this attribute in your <td> tag: width="40px" (example only - change it however you like). You can also change height in the same way, with the height="20px" attribute.

Upvotes: 0

mara
mara

Reputation: 1

The problem was in styling each <td>'s width within an echo statement. The solution was to simply use single quotes instead of double quotes

<td width='130px'>$item</td> this one was correct inside of echo"";

<td width="130px">$item</td>

I could also use <td id='cell1'>$item</td> and and style with:

<style> td#cell1{width:130px;} </style>

Upvotes: 0

Nirmohi
Nirmohi

Reputation: 128

You can use like this.

<table>
    <tr>
        <th width="200"></th>
        <th width="100"></th>
        <th width="100"></th>
     </tr>
</table>

You can put width attribute with pixel / % format. (example: width="50") (example: width="50%")

Reference : https://www.w3schools.com/tags/att_table_width.asp

Upvotes: 0

t..
t..

Reputation: 1101

<style>
td {
   width:130px;
}
</style>

this is using css styling, specifying the width for the <td>'s

Upvotes: 1

Related Questions