ASP.net - 中心对齐面板?

时间:2012-07-21 20:24:29

标签: asp.net html alignment panel center

我需要对齐一个面板。我使用以下内容:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestDefault.aspx.cs" Inherits="tregware.TestDefault" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel ID="Root" runat="server" BackColor="Red"  HorizontalAlign="Center" Style="left: 0px; top: 0px; width: 100%; height: 100%; position: absolute; z-index: 0;">


<asp:Panel ID="Body" runat="server" BackColor="Blue" 
    Style="left: 0px; top: 24px;width: 800px; height: 100%; position: absolute; z-index: 0;" 
    HorizontalAlign="Center">
</asp:Panel>

</asp:Panel>
</form>
</body>
</html>

然而,面板(“身体”)不会居中。我该怎么做?

3 个答案:

答案 0 :(得分:2)

您已经设置了position: absolute,因此您用来居中元素的许多常规方法可能无法正常工作。

由于您已设置固定width 800px,因此您可以使用:

Style="left: 50%; margin-left: -400px; ..."

答案 1 :(得分:1)

Panel具有 Horizo​​ntalAlign

的属性
<asp:Panel id="reqId" runat="server" HorizontalAlign="center" >
Your Text Here
</asp:Panel>

答案 2 :(得分:0)

创建名为.panel { align:center }

的css

然后将其添加到面板CssClass = "panel"

相关问题