0

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 
Didix
  • 567
  • 1
  • 7
  • 26
mara
  • 1
  • 1
  • 1
    `I've read that the way to do it is by using css: td style="width:130px"` The way to do it is to use CSS, in a ` – CertainPerformance Jun 18 '18 at 02:16
  • Possible duplicate of [Set the table column width constant regardless of the amount of text in its cells?](https://stackoverflow.com/questions/4457506/set-the-table-column-width-constant-regardless-of-the-amount-of-text-in-its-cell) – hungrykoala Jun 18 '18 at 02:50
  • Do you have a stylesheet/.css file? If not create one [and learn what it stand for](https://www.w3schools.com/html/html_css.asp) – Didix Jun 18 '18 at 06:14

4 Answers4

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

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

t..
  • 1,101
  • 1
  • 9
  • 22
0

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

Nirmohi
  • 128
  • 1
  • 10
0

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.

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
0

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>

mara
  • 1
  • 1