[英]Centering contents of a div - using CSS
I have the following source in a user control: 我在用户控件中具有以下来源:
<asp:Panel runat="server" ID="PanelParametersList" CssClass="AccessReportParameterControls"></asp:Panel>
<div class = "buttonpanel">
<asp:Button ID="Button1" runat="server" Text="View Report"
onclick="Button1_Click"></asp:Button>
<asp:Button ID="Button2" runat="server" Text="Back"
onclick="Button2_Click"></asp:Button>
</div>
In the header of the containing aspx page I am adding css styles: 在包含aspx页面的标题中,我添加了css样式:
<style type="text/css">
.ReportViewer_AccessReportViewer { position:absolute; top:50px; }
.ReportViewer_AccessReportViewer_noparams { position:absolute; top:0px; }
.AccessReportParameterControls {width: 100%; background-color: #E4E4EC; padding: 5px; }
.ParameterContainer {width: 100%;}
.ParameterControlLabel {padding:0, 10, 0, 10;}
.AccessReportParameters {width: 100%;}
.buttonpanel {margin:0 auto; }
</style>
I am trying to center the contents of the button panel div but am having no luck.....any ideas? 我试图将按钮面板div的内容居中,但是没有运气.....任何想法吗?
用于在div中居中放置内容
text-align:center;
<div class = "parent">
<button />
</div>
Style: 样式:
.parent{
text-align:center;
}
This is all you need to do. 这就是您需要做的。 Set the
text-align
to center
in any parent container and the inline
elements will follow the rule. 将
text-align
设置为在任何父容器的center
, inline
元素将遵循规则。
As a good practice I would advice you to place your styles in a different style.css
file and place this in your .asp files: 作为一种好习惯,我建议您将样式放置在另一个
style.css
文件中,并将其放置在您的.asp文件中:
<link href="style.css" rel="stylesheet" type="text/css" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.