Html ASP.net - 中心对齐面板?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11595585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.net - Center Align Panel?
提问by derp_in_mouth
I need to center align a panel. I use the following:
我需要居中对齐面板。我使用以下内容:
<%@ 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>
However the panel ("Body") will not center. How would I do so?
但是面板(“Body”)不会居中。我该怎么做?
回答by Zhihao
You've set position: absolute
, so a lot of the regular methods you would use to center elements probably won't work.
您已经设置了position: absolute
,因此您用来将元素居中的许多常规方法可能都不起作用。
Since you've set a fixed width
of 800px
, you could use:
由于您设置了固定width
的800px
,您可以使用:
Style="left: 50%; margin-left: -400px; ..."
回答by Syed Ali Taqi
Panel has the property of HorizontalAlign
面板具有HorizontalAlign属性
<asp:Panel id="reqId" runat="server" HorizontalAlign="center" >
Your Text Here
</asp:Panel>
回答by HatSoft
Create a css called .panel { align:center }
创建一个名为 .panel { align:center }
and then add it to the panel CssClass = "panel"
然后将其添加到面板 CssClass = "panel"