Solved

Centering my label and button in HTML

Posted on 2014-07-24
5
344 Views
Last Modified: 2014-07-29
I have a form and this one section that I attached is bothering me. I have an imagebutton and I am trying to center the lable and button that are in a <td> next to the imagebutton. Look at the pic attached and even though the lable and button are centered, I need it centered as if the image button wasnt there. My code is below and I am kinda new to HTML and designing these pages so go easy on me. Again, I need the label and button in the middle of the entire row and not in the middle of the row after the width of the imagebutton is taken into account. I was thinking the imagebuttons width is 120px so if I could center the lable and button and then minus the 120 that would work but like I said Im new and dont know how to do it...Anyway, heres my code and I have attached a pic...Thanks all

Markup code...
         
  <asp:Panel ID="Panel16" runat="server" HorizontalAlign="Center" Width="973px">
                <table style="width: 100%;" align="center">
                    <tr>
                        <td style="width:120px;text-align:left;vertical-align:top;">
                            <asp:UpdatePanel ID="upAddNew" runat="server" UpdateMode="Always">
                                <ContentTemplate>
                                    <asp:ImageButton ID="btnAddNew" runat="server" OnCommand="btnAddNew_OnCommand" CommandName="AddVendors" Height="30px" Width="120px" ToolTip="Add vendor" />                                        
                                </ContentTemplate>
                            </asp:UpdatePanel> 
                        </td>
                        <td>
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <ContentTemplate>
                                    <asp:Label ID="lblMsg" runat="server" CssClass="label" Visible="False" ForeColor="Red"></asp:Label>
                                    <br />
                                    <asp:Button ID="btnOK" runat="server" Text="OK" Visible="False" Width="69px" />
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                    </tr>
                </table>
            </asp:Panel>

Open in new window

Pic of my panel
0
Comment
Question by:jknj72
  • 3
5 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40217366
I'm not a .NET Dev but it seems like you really  need front end help.  See if this sample helps you out.  You really just need to give the td you want centered a style, "text-align:center"

I have made a table and outlined the table in red and td's in black for show.

http://jsbin.com/baxup/1/edit
<!DOCTYPE html>
<html>
<head>
  <style>
  table{
    width:600px;
    border:solid red;
  }
  td {border:solid thin;}
  td.foo{
    text-align:center;
    
  }
  </style>
  <meta charset="utf-8">
  <title>Padas</title>
</head>
<body>
<table>
  <tr><td>First Row</td></tr>
  <tr><td class="foo">Item 1<br>Item 2</td></tr>
</body>
</html>

Open in new window

0
 

Author Comment

by:jknj72
ID: 40217644
that would work but I have too much going on with the page to insert another row. It wont look right. I want to have it in the same <tr> but centered. I was thinking if I could maybe do a colspan  of maybe 11 for instance and have the imagebutton in the 1st col and then find where the middle of the colspan would be(im thinking 6) and put my label and button there. Any thoughts?
0
 

Accepted Solution

by:
jknj72 earned 0 total points
ID: 40217704
I think I got it....I put in a colspan=6 and put the imagebutton in the 1st col and 2nd col=20% and 3rd col=20% with the label and button in this col. then another 2 cols at 20% and it worked like a charm.....Thanks for your help!!new look
           <asp:Panel ID="Panel16" runat="server" HorizontalAlign="Center" Width="973px" >
                <table style="width: 100%;" align="center">
                    <tr>
                        <td style="width:20%;text-align:left;vertical-align:top;">
                            <asp:UpdatePanel ID="upAddNew" runat="server" UpdateMode="Always">
                                <ContentTemplate>
                                    <asp:ImageButton ID="btnAddNew" runat="server" OnCommand="btnAddNew_OnCommand" CommandName="AddVendors" Height="30px" Width="120px" ToolTip="Add vendor" />                                        
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                        <td style="width:20%;">
                            &nbsp;
                        </td>

                        <td style="width:20%;">
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <ContentTemplate>
                                    <asp:Label ID="lblMsg" runat="server" CssClass="label" Visible="False" ForeColor="Red"></asp:Label>
                                    <br />
                                    <asp:Button ID="btnOK" runat="server" Text="OK" Visible="False" Width="69px" />
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                        <td style="width:20%;">
                            &nbsp;
                        </td>
                        <td style="width:20%;">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </asp:Panel>
0
 

Author Closing Comment

by:jknj72
ID: 40226233
I was able to figure it out so I posted the solution. I know its not rocket science but its good for me!!!
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

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
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