How to align form at the center of the page in html/css

后端 未结 6 500
粉色の甜心
粉色の甜心 2021-02-05 13:28

I am new to html/css. i am trying to build up my own form and i am trying to align it in the center. I used the align property in css but its not working.

Html code:

相关标签:
6条回答
  • 2021-02-05 13:55

    Or you can just use the <center></center> tags.

    0 讨论(0)
  • 2021-02-05 13:58
    1. Wrap the element inside a div container as a row like your form here or something like that.
    2. Set css attribute:
      • width: 30%; (or anything you want)
      • margin: auto; Please take a look on following picture for more detail.
    0 讨论(0)
  • 2021-02-05 14:01

    This is my answer. I'm not a Pro. I hope this answer may help you :3

    <div align="center">
    <form>
    .
    .
    Your elements
    .
    .
    </form>
    </div>
    
    0 讨论(0)
  • 2021-02-05 14:08

    Like this

    demo

    css

        body {
        background-color : #484848;
        margin: 0;
        padding: 0;
    }
    h1 {
        color : #000000;
        text-align : center;
        font-family: "SIMPSON";
    }
    form {
        width: 300px;
        margin: 0 auto;
    }
    
    0 讨论(0)
  • 2021-02-05 14:13

    Wrap the <form> element inside a div container and apply css to the div instead which makes things easier.

    #aDiv{width: 300px; height: 300px; margin: 0 auto;}
    <html>
    
    <head></head>
    
    <body>
      <div>
        <form>
          <div id="aDiv">
            <table>
              <tr>
                <td>Name :</td>
                <td>
                  <input type="text" name="name">
                </td>
                <br>
              </tr>
              <tr>
                <td>Email :</td>
                <td>
                  <input type="text" name="email">
                </td>
                <br>
              </tr>
              <tr>
                <td>Password :</td>
                <td>
                  <input type="password" name="pwd">
                </td>
                <br>
              </tr>
              <tr>
                <td>Confirm Password :</td>
                <td>
                  <input type="password" name="cpwd">
                  <br>
              </tr>
              <tr>
                <td>
                  <input type="submit" value="Submit">
                </td>
              </tr>
            </table>
          </div>
        </form>
      </div>
    </body>
    
    </html>

    0 讨论(0)
  • 2021-02-05 14:18

    I would just use table and not the form. Its done by using margin.

    table {
      margin: 0 auto;
    }
    

    also try using something like

    table td {
        padding-bottom: 5px;
    }
    

    instead of <br />

    and also your input should end with /> e.g:

    <input type="password" name="cpwd" />
    
    0 讨论(0)
提交回复
热议问题