HTML:我如何对齐此表单?

时间:2014-03-22 02:54:13

标签: html forms

我的代码中有一个表单,但它位于页面的左侧。我不知道如何对齐它。

 <form method="post" action="#">
  <div class="5grid">
    <div class="row">
      <div class="6u">
        <input type="text" name="name" id="name" placeholder="Name">
      </div>
      <div class="6u">
        <input type="text" name="email" id="email" placeholder="Email">
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <input type="text" name="subject" id="subject" placeholder="Subject">
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <textarea name="message" id="message" placeholder="Message"></textarea>
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <input type="submit" class="button" value="Send Message">
        <input type="reset" class="button button-alt" value="Clear Form">
      </div>
    </div>
  </div>
</form>

它看起来像这样:

任何帮助表示感谢。

2 个答案:

答案 0 :(得分:1)

如果您只想将其水平居中,请将您的表单放在宽度受限的div父级和一个带有居中内容的doc-wide div祖父母中:

<div style="text-align: center">
 <div style="width: 400px; text-align: left;">
  <form ...
  ...
  </form>
 </div>
</div>

答案 1 :(得分:1)

<style media="screen" type="text/css">

form {
width: 400px; 
margin: 0 auto; 
} 

</style>
 <form method="post" action="#">
  <div class="5grid">
    <div class="row">
      <div class="6u">
        <input type="text" name="name" id="name" placeholder="Name">
      </div>
      <div class="6u">
        <input type="text" name="email" id="email" placeholder="Email">
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <input type="text" name="subject" id="subject" placeholder="Subject">
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <textarea name="message" id="message" placeholder="Message"></textarea>
      </div>
    </div>
    <div class="row">
      <div class="12u">
        <input type="submit" class="button" value="Send Message">
        <input type="reset" class="button button-alt" value="Clear Form">
      </div>
    </div>
  </div>
</form>

这应该有效