Solved

Centering my label and button in HTML

Posted on 2014-07-24
5
331 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now