Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up fixed width for <td>?

Simple scheme:

  <tr class="something">     <td>A</td>     <td>B</td>     <td>C</td>     <td>D</td>   </tr> 

I need to set up a fixed width for <td>. I've tried:

tr.something {   td {     width: 90px;   } } 

Also

td.something {   width: 90px; } 

for

<td class="something">B</td> 

And even

<td style="width: 90px;">B</td> 

But the width of <td> is still the same.

like image 933
user984621 Avatar asked Feb 27 '13 14:02

user984621


People also ask

How do you set fixed width in TD?

By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.

How do I set the width of a TD table?

To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.

How do I make TD the same width?

Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.

How do you set a fixed column width?

Select your table. On the Layout tab, in the Cell Size group, click AutoFit. Click Fixed Column Width.


1 Answers

For Bootstrap 4.0:

In Bootstrap 4.0.0 you cannot use the col-* classes reliably (works in Firefox, but not in Chrome). You need to use OhadR's answer:

<tr>   <th style="width: 16.66%">Col 1</th>   <th style="width: 25%">Col 2</th>   <th style="width: 50%">Col 4</th>   <th style="width:  8.33%">Col 5</th> </tr> 

For Bootstrap 3.0:

With twitter bootstrap 3 use: class="col-md-*" where * is a number of columns of width.

<tr class="something">     <td class="col-md-2">A</td>     <td class="col-md-3">B</td>     <td class="col-md-6">C</td>     <td class="col-md-1">D</td> </tr> 

For Bootstrap 2.0:

With twitter bootstrap 2 use: class="span*" where * is a number of columns of width.

<tr class="something">     <td class="span2">A</td>     <td class="span3">B</td>     <td class="span6">C</td>     <td class="span1">D</td> </tr> 

** If you have <th> elements set the width there and not on the <td> elements.

like image 156
Paulo Avatar answered Sep 16 '22 15:09

Paulo