I am dynamically generating a table using AJAX. The structure of the table to be populated is as follows:
<table id="foobar" style="width:100%">
<thead>
<tr>
<th style="width:20%;"></th>
<th style="width:55%;"></th>
<th title="widget name">Name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
The cell data contains either:
I tried the following:
valign="top"
(separately) at the table
, th
and tr
levels - it had no effectstyle="vertical-align: top;"
(separately) at the table
, th
and tr
levels - it had no effectI don't want to set the align property at the cell level because it will cause too much unnecessary bloat if the table contains several (say hundreds of) rows.
How can I force a table to vertically align its cell contents to top (bearing in mind that the cells contain block elements?
Highlighted text, right clicked in the table and chose Table Properties > Cell > Vertical Options > Bottom.
The HTML <table> align Attribute is used to specify the alignment of the table and its content. Note : This attribute is not supported by HTML5. Attribute Values: left: It sets the left align to the table.
We use the CSS property text-align, to center align text in table cells. We use inline, internal style sheet for text alignment in table cells. The text-align property of CSS sets the alignment of the content in <th> and <td>. By default, the content of <th> are center-aligned and the content of <td> are left-aligned.
Here is a basic table example with TH and TD tags where the content is set to "vertical-align:top".
Demo: http://jsfiddle.net/HAQ3s/472/
th, td {
vertical-align: top;
}
<table>
<tr>
<th>A<br /><br /></th>
<th>B</th>
<th>C</th>
</tr>
<tr>
<td>1<br /><br /></td>
<td>2</td>
<td>3</td>
</tr>
</table>
valign
should work no matter what if all settings that we see here are those that are actually used.
But I suspect a different gunman here. Did you check your global CSS file what it defines for TH
elements? Maybe that's what's giving you headaches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With