Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<TD> tag ignoring width in CSS

Tags:

html

css

I have a table that I have been successfully able to highlight the correct cells with a selector. However the width tag is being ignored. Can someone explain why the widths of the cells aren't affected?

Here is the jsfiddle.

HTML:

<table border="1">
    <tr>
        <th>ID</th>
        <th>Title</th>
    </tr>
    <tr>
        <td>Test Title</td>
        <td>1</td>
    </tr>
    <tr>
        <td>Test Title</td>
        <td>1</td>
    </tr>
</table>
<div class="middle">
<table border="1" width="100%">     
    <tr>
        <th>Test Col 1</th>
        <th>Test Col 2</th>
        <th>Test Col 3</th>
        <th>Test Col 4</th>
        <th>Test Col 5</th>
        <th>Test Col 6</th>
     </tr>
     <tr>
        <td>Col 1</td>
        <td>Col 2</td>
        <td>Col 3</td>
        <td>Col 4</td>
        <td>Col 5</td>
        <td>Col 6</td>
     </tr>
     <tr>
        <td>Col 1</td>
        <td>Col 2</td>
        <td>Col 3</td>
        <td>Col 4</td>
        <td>Col 5</td>
        <td>Col 6</td>
     </tr>
     </table>
</div>
<table border="1">
    <tr>
        <th>LINKS</th>
    </tr>
    <tr>
        <td>LINK 1  | LINK 2</td>
    </tr>
    <tr>
        <td>LINK 1  | LINK 2</td>
    </tr>
</table>

CSS:

table { float:left; }
.middle {  float:left; width:350px; overflow:auto;}
.middle table td, .middle table th { width:300px; background:red; }
like image 775
Jon Harding Avatar asked May 07 '13 15:05

Jon Harding


1 Answers

width property of td and th elements is not supported at HTML5, still you can get a workaround by setting their display to inline-block and setting their width via CSS.

like image 55
Pavel Avatar answered Oct 26 '22 12:10

Pavel