Solved

vert align text in table cell - css jquery solution

Posted on 2013-01-11
8
696 Views
Last Modified: 2013-01-14
Amazing how fast this knowledge leaves you if you don't use it every day.

How do you vertically align (actually, vertically align and right justify) text in a table cell ( <td> ) so that it is centered in the cell and aligned with the control in the next cell?

screenshot:

vert align text
markup:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AgentFormEdit.ascx.cs" Inherits="Reo.ContentControls.AgentFormEdit" %>
<%@ Register Assembly="Framework" Namespace="Framework.UIControls" TagPrefix="cc1" %>


<div id="frame">
    <div id="frame_header">
        <div id="frame_title">
            <h1>
                Edit Agent Form</h1>
        </div>
    </div>

   <%-- <asp:UpdatePanel ID="UpdatePanelAgentFormAdd" runat="server" 
        ChildrenAsTriggers="False">
    <ContentTemplate>--%>
    <div id="corpus">
        <table class="layout_table">
            <tr><td>Form Type</td><td><cc1:DdlLookup runat="server" HeaderCode="DocType" ID="ddlLookupFormType"></cc1:DdlLookup></td></tr>
            <tr><td>Sequence</td><td><asp:TextBox ID="TextBoxSequence" runat="server"></asp:TextBox></td></tr>
            <tr><td>Form Name</td><td><asp:TextBox ID="TextBoxFormName" runat="server"></asp:TextBox></td></tr>
            <tr><td>Colist</td><td><asp:TextBox ID="TextBoxColist" runat="server"></asp:TextBox></td></tr>
            <tr><td>Acceptance Reqd</td><td><asp:TextBox ID="TextBoxAcceptanceReqd" runat="server"></asp:TextBox></td></tr>
            <tr><td>Duplicates Allowed</td><td><asp:TextBox ID="TextBoxDuplicatesAllowed" runat="server"></asp:TextBox></td></tr>
            <tr><td>External Link</td><td><asp:TextBox ID="TextBoxExternalLink" runat="server"></asp:TextBox></td></tr>
            <tr><td>Task Code</td><td><asp:TextBox ID="TextBoxTaskCode" runat="server"></asp:TextBox></td></tr>
            <tr><td>AM firm</td><td><asp:TextBox ID="TextBoxAMFirm" runat="server"></asp:TextBox></td></tr>
            <tr><td>Client</td><td><asp:TextBox ID="TextBoxClient" runat="server"></asp:TextBox></td></tr>
            <tr><td>Product</td><td><asp:DropDownList ID="ddlProducts" runat="server"></asp:DropDownList></td></tr>
            <tr><td>Active</td><td><asp:TextBox ID="TextBoxActive" runat="server"></asp:TextBox></td></tr>
        </table>
    </div>
 <%--   </ContentTemplate>
    </asp:UpdatePanel>--%>

    <div id="footer">
    </div>
</div>
<div id="end_cap">
</div>

Open in new window


please provide CSS and / or jQuery type solution (one of each ideal)
0
Comment
Question by:knowlton
8 Comments
 
LVL 30

Expert Comment

by:LZ1
ID: 38767884
First here's reference:
http://phrogz.net/css/vertical-align/index.html

Now here's some code:
.layout_table tr td{vertical-align:middle;}

Open in new window


In your HTML:
<table class="layout_table">
    <tr><td valign="middle">Form Type</td><td><cc1:DdlLookup runat="server" HeaderCode="DocType" ID="ddlLookupFormType"></cc1:DdlLookup></td></tr>
    <tr><td valign="middle">Sequence</td><td><asp:TextBox ID="TextBoxSequence" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Form Name</td><td><asp:TextBox ID="TextBoxFormName" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Colist</td><td><asp:TextBox ID="TextBoxColist" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Acceptance Reqd</td><td><asp:TextBox ID="TextBoxAcceptanceReqd" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Duplicates Allowed</td><td><asp:TextBox ID="TextBoxDuplicatesAllowed" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">External Link</td><td><asp:TextBox ID="TextBoxExternalLink" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Task Code</td><td><asp:TextBox ID="TextBoxTaskCode" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">AM firm</td><td><asp:TextBox ID="TextBoxAMFirm" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Client</td><td><asp:TextBox ID="TextBoxClient" runat="server"></asp:TextBox></td></tr>
    <tr><td valign="middle">Product</td><td><asp:DropDownList ID="ddlProducts" runat="server"></asp:DropDownList></td></tr>
    <tr><td valign="middle">Active</td><td><asp:TextBox ID="TextBoxActive" runat="server"></asp:TextBox></td></tr>
</table>

Open in new window


You really don't need jQuery to do this. CSS and good HTML coding practices should do it for you.
0
 
LVL 5

Author Comment

by:knowlton
ID: 38767939
<tr><td valign="middle">Form Type</td><td><cc1:DdlLookup runat="server" HeaderCode="DocType" ID="ddlLookupFormType"></cc1:DdlLookup></td></tr>

This did not seem to work.
0
 
LVL 30

Assisted Solution

by:LZ1
LZ1 earned 50 total points
ID: 38767945
Do you have any styling on the internal <asp> tags on the rendered page?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Assisted Solution

by:tap52384
tap52384 earned 50 total points
ID: 38769008
From a design standpoint, it looks good the way it is. You could use text-align:right to align the text in the cell. Additionally, to make the text centered in the cell, you could set the line-height of the cell to the height of the cell. That could work.
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 400 total points
ID: 38769129
<td valign="middle">

Is obsolete.  Use CSS or run the risk of watching it break.

Cd&
0
 
LVL 5

Author Comment

by:knowlton
ID: 38774901
Maybe not the best, but this seems to be working:

This css seems to align the text vertically.  It's not perfect, but I eyeballed it and it works for me.  My boss indicated that since this is purely an internal tool (for us) it's okay not to be perfect:


         $('div[class="afa_label"]').css('padding-top', '5px');

   $(document).ready(function () {
         $('div[id="agentformfields"]').css('position', 'relative');
         //$('div[id="agentformfields"]').css('background-color', 'red');
         $('div[id="agentformfields"]').css('height', '500px');
         $('div[id="agentformfields"]').css('width', '800px');

         $('div[class="afa_label"]').css('position', 'relative');
         $('div[class="afa_label"]').css('width', '120px');
      //   $('div[class="afa_label"]').css('background-color', 'red');
         $('div[class="afa_label"]').css('float', 'left');
         $('div[class="afa_label"]').css('clear', 'left');
         $('div[class="afa_label"]').css('text-align', 'right');
         $('div[class="afa_label"]').css('margin-right', '5px');
         $('div[class="afa_label"]').css('padding-top', '5px');


         $('div[class="afa_control"]').css('position', 'relative');
         $('div[class="afa_control"]').css('width', '280px');      
         $('div[class="afa_control"]').css('float', 'left'); 
         
         $('input').css('width', '30px');
         $('input[name*="TextBoxExternalLink"]').css('width', '200px');
         $('input[name*="TextBoxFormName"]').css('width', '200px');
         $('select[name*="TextBoxExternalLink"]').css('width', '200px');

         $('div[class="afa_controlrb"]').css('position', 'relative');
         $('div[class="afa_controlrb"]').css('width', '80px');
         $('div[class="afa_controlrb"]').css('float', 'left');

         $('div[class="afa_button"]').css('position', 'relative');
         $('div[class="afa_button"]').css('width', '150px');
         $('div[class="afa_button"]').css('float', 'left');


         $('input[type="submit"]').css('width', '80px');
         $('input[type="submit"]').css('position', 'relative');
         $('input[type="submit"]').css('float', 'left');       
     });

     

Open in new window

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 38774933
Thanks everyone...
0
 
LVL 5

Author Comment

by:knowlton
ID: 38774950
See...I think it looks better now...

new vert aligned
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question