Solved

Centering my label and button in HTML

Posted on 2014-07-24
5
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 53

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

632 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