Solved

Centering my label and button in HTML

Posted on 2014-07-24
5
307 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 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

6 Experts available now in Live!

Get 1:1 Help Now