CSS 如何在表单中居中一个 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3616112/
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
How to center one div in form
提问by shamim
I work on C# Asp.net
我在 C# Asp.net 上工作
Main div ---- table
主div----表格
want to show this div on middle of the form.i want to build a login form.my table contain
想在表单中间显示这个 div。我想建立一个登录表单。我的表包含
User name:**(it's a lable,on browser it's broken like user
name : show why?)**
password:
<div id="main">
<table width="600px" border="1">
<tr>
<td>
<asp:Label ID="Label1" runat="server" CssClass="cssLabel" Text="User Name :"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server" CssClass="cssLabel" Text="Password :"></asp:Label>
</td>
</tr>
</table>
</div>
want to show div on middle of the form? and why my lable text are going to broken how to solve it?
想要在表单中间显示 div?为什么我的标签文字会损坏如何解决?
if u gone to google.com than you see text box take position on middle of the frame.i want this .i want my controls also take position on the middle of the frame.How to do that?
如果你访问 google.com,你会看到文本框位于框架的中间。我想要这个。我希望我的控件也位于框架的中间。怎么做?
回答by Sandeep Pathak
You can use this to show idiv n the middle of the form:-
您可以使用它在表单中间显示 idiv n:-
<div style="margin-left:auto;margin-right:auto;">Put the controls here </div>
回答by Mr Grok
You've edited your question now so this doesn't give you the exact code you need, but would help you work it out / others who view your question with a similar problem. So here goes... you need something like this:
您现在已经编辑了您的问题,因此这不会为您提供所需的确切代码,但会帮助您解决问题/其他查看您问题的类似问题的人。所以这里......你需要这样的东西:
<style type="text/css">
.wrp { width: 100%; text-align: center; }
.frm { text-align: left; width: 500px; margin: auto; border: 1px solid black; }
.fldLbl { white-space: nowrap; }
</style>
<div class="wrp">
<div class="frm">
<span class="fldLbl">User name:</span>
</div>
</div>
回答by Stephen Mwanzia
try this option, that is style the div
with style="width:100%;text-align:center"
试试这个选项,即风格div
与style="width:100%;text-align:center"