简体   繁体   中英

How to align a label to the top of a row in a table asp.net C#

I have a table in my asp.net page. The controls that I am trying to align is a label, and a textbox. I have both controls in one row in the table. No matter how I try to align the label, it displays from the bottom of the row. How can I align the label to display in the center or the top of the row?

Here is my html aspx code:

<tr>
            <td colspan="4">
                <span>
                    <asp:Label class="field" ID="Label9" runat="server" Text="Comments:"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;
    <asp:TextBox ID="TB_Comments" runat="server" TextMode="MultiLine" Width="500px" Height="50px"></asp:TextBox>
                </span>

            </td>
        </tr>    

Here is my style code:

<style type="text/css">   
.field label,
.field select
{
    display: inline-block;
    vertical-align: top;

}
    </style>

Also is there a way for me to align the label control to the top or center via the codebehind and not using HTML? Thanks for any input.

Use css classes for this. ie

 <td class="label_topped">
    <asp:Label ID="Label1" runat="server" Text="PO Number:"></asp:Label> 
 </td>

where the class will be:

.label_topped {
  vertical-align:top;
 }

note the class is applied to the cell () and not the label.

A quicker alternative is to do a direct style on the cell ie

 <td style="vertical-align:top">
   <asp:Label ID="Label1" runat="server" Text="PO Number:"></asp:Label> 
 </td>

hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM