CSS 如何将输入表单放置在页面中央?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1582284/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 21:10:02  来源:igfitidea点击:

How to position an input form at the center of a page?

css

提问by Anand

I want to position a registration from at the center of a page.

我想从页面的中心定位一个注册。

please tell me how should i do that

请告诉我该怎么做

回答by Wayne Hartman

Encapsulate it in a div with the following CSS attributes:

使用以下 CSS 属性将其封装在一个 div 中:

<div style="width:400px; margin-right:auto; margin-left:auto; border:1px solid #000;">
    <form action="helloWorld">
        <Some markup>
    </form>
</div>

回答by user2395366

Just use:

只需使用:

<div style="margin:0 auto" align=center>
 <input button>
</div>

回答by Michael Holland

I created a .CSS file with the following:

我创建了一个 .CSS 文件,内容如下:

form {width: 40%;
      margin-right: 30%;
      margin-left: 30%;
      background-color: green}

div.mainform {width:100%;
              border:1px solid #000}

Then in the HTML document I used.

然后在我使用的 HTML 文档中。

<DIV ID="MAINFORM">
    <FORM>
        Other HTML Markup
    </FORM>
</DIV>