Solved

Centering my label and button in HTML

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 48
SlickNav Menu Plugin Not appearing on mobile 6 33
How to change the link of an image using md5 in php ? 3 32
Linq asp.net mvc 13 8
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…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

770 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