Vertical Alignment of text in a table cell

HtmlCss

Html Problem Overview


Here's a portion of my table (it's a form):

Those are just two <td>'s in a <tr>. I'm trying to get Description up top, to the top of the table cell, rather than resting on the bottom.

How can I do that?

Html Solutions


Solution 1 - Html

td.description {vertical-align: top;}

where description is the class name of the td with that text in it

td.description {
  vertical-align: top;
}

<td class="description">Description</td>

OR inline (yuk!)

<td style="vertical-align: top;">Description</td>

Solution 2 - Html

Try

td.description {
  line-height: 15px
}

<td class="description">Description</td>

Set the line-height value to the desired value.

Solution 3 - Html

valign="top" should do the work.

<tr>
  <td valign="top">Description</td>
</tr>

Solution 4 - Html

If you are using Bootstrap, please add the following customised style setting for your table:

.table>tbody>tr>td, 
.table>tbody>tr>th, 
.table>tfoot>tr>td, 
.table>tfoot>tr>th, 
.table>thead>tr>td, 
.table>thead>tr>th {
      vertical-align: middle;
 }

Solution 5 - Html

I had the same issue but solved it by using !important. I forgot about the inheritance in CSS. Just a tip to check first.

Solution 6 - Html

Just add vertical-align:top for first td alone needed not for all td.

tr>td:first-child {
  vertical-align: top;
}

<tr>
  <td>Description</td>
  <td>more text</td>
</tr>

Solution 7 - Html

CSS {vertical-align: top;} or html Attribute {valign="top"}

.table td, 
.table th {
    border: 1px solid #161b21;
    text-align: left;
    padding: 8px;
    width: 250px;
    height: 100px;
    
    /* style for table */
}

.table-body-text {
  vertical-align: top;
}

<table class="table">
    <tr>
      <th valign="top">Title 1</th>
      <th valign="top">Title 2</th>
    </tr>
    <tr>
      <td class="table-body-text">text</td>
      <td class="table-body-text">text</td>
    </tr>
   </table>

For table vertical-align we have 2 options.

  1. is to use css {vertical-align: top;} >

  2. another way is to user attribute "valign" and the property should be "top" {valign="top"}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAKorView Question on Stackoverflow
Solution 1 - HtmlclairesuzyView Answer on Stackoverflow
Solution 2 - HtmlDTSView Answer on Stackoverflow
Solution 3 - HtmlmorgarView Answer on Stackoverflow
Solution 4 - HtmlRichardView Answer on Stackoverflow
Solution 5 - HtmlRazziView Answer on Stackoverflow
Solution 6 - HtmlManoView Answer on Stackoverflow
Solution 7 - HtmlA.S.AbirView Answer on Stackoverflow