2011-07-28 11 views
0

我想垂直對齊面板中的表,但我不能,當我應用風格屬性到表不工作?係指我的代碼在下面給出會有上沒有樣式屬性的效果,如何定位面板內C#Web應用程序?

<asp:Panel ID="Panel1" runat="server" 
     style="z-index:0;left:250px;position:absolute;top:160px; height: 160px; padding:10" 
     BackColor="Green" Width="300px"> 
     <div style="width: 295px; height: 155px;" align= "center"> 
     <table style="height: 48px; width: 187px; margin-left:0px; min-height:14px; min-width:55px; vertical-align:bottom" align="center" bgcolor="green" > 
    <tr> 
    <td> 
     <asp:Label ID="Label2" runat="server" Text="UserName" ForeColor="White"></asp:Label> 
    </td> 
    <td> 
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    </td> 
    </tr> 
    <tr> 
    <td> 
     <asp:Label ID="Label3" runat="server" Text="Password" ForeColor="White"></asp:Label> 
    </td> 
    <td> 
     <asp:TextBox ID="TextBox2" textmode="Password" runat="server"></asp:TextBox> 
    </td> 
    </tr> 
    <tr> 
    <td> 
     <asp:Label ID="Label4" runat="server" ForeColor="White"></asp:Label> 
    </td> 
    <td> 
     <asp:Button ID="Button1" runat="server" Text="Login" onclick="Button1_Click" /> 
    </td> 
    </tr> 
    </table> 
    </div> 
    </asp:Panel> 

的希望您的建議

回答

0

父容器內的一些內容的垂直對齊方式始終是棘手的,如果你不知道內容的高度。解決方案是在父代&內容元素之間有一個包裝div。然後有外部容器與"display:table"和包裝div與"display:table-cell"中間垂直對齊。看到這個搗鼓插圖:http://jsfiddle.net/myXL3/3/

的完整信息這一做法,看到這樣優秀的文章:http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

+0

你是正確的,但它不是爲我工作,我不知道爲什麼?但它應該! –

0

這裏的問題是,你有一個div元素中的表格。將vertical-align:middle添加到div的風格應該可行。這假定div總是比表格「高」(如在你的代碼片段中)。

(另外,你有你的table的風格利潤 - 它們應該被刪除,以確保它們不與垂直對齊干擾)

相關問題