0

I've been looking for this in google and it says that the css code is margin: 0 auto;. I tried it and it doesn't work for me. Please help. Thanks in advance.

login.html

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Log In</title>
 <link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
 <div id="formLogin">
    <table class="formTable">
        <tr>
            <td>Username: </td>
            <td> <input type="text" id="loginusername" name="loginusername"/>  </td>
        </tr>

        <tr>
            <td>Password: </td>
            <td> <input type="password" id="loginpassword" name="loginpassword"/>  </td>
        </tr>

    </table>

    <div align="center">
        <input type="submit" id="btnlogin" name="btnlogin" value="Log In"/>
        <input type="submit" id="btncancelogin" name="btncancelogin" value="Cancel"/>
    </div>
 </div>

</body>
</html>

stylesheet.css

table.formTable {
 margin-left: auto;
 margin-right: auto;
}

table.formTable td {
 padding: 8px;
}

#formLogin {
 width: 360px;
 background-color: #eeeeee;
 margin: 0 auto;
 padding: 20px;
 -moz-border-radius:    10px;
 -webkit-border-radius: 10px;
 border-radius:         10px;
}
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
NinjaBoy
  • 3,715
  • 18
  • 54
  • 69

3 Answers3

0

If you want to center it vertically also try reading this.

Update:

Try this code. Of course you can move CSS out to your css file. Tested in IE9 and FF6:

<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Log In</title>
 <link rel="stylesheet" type="text/css" href="stylesheet.css" />
<style type="text/css">
#wrapper{
    background-color: #ccf;
    position: relative;
    text-align: left;
    width: 100%;
    height: 100%;
    margin: 0px auto;

    }
#content{   
    background-color: transparent;
    position: absolute;
    top: 40%;
    left: 0px;
    width: 100%;
    margin-top: auto;
    text-align: center;
    min-width: 900px; 
}
table.formTable {
 margin-left: auto;
 margin-right: auto;
}

table.formTable td {
 padding: 8px;
}

#formLogin {
 width: 360px;
 background-color: #eeeeee;
 margin: 0 auto;
 padding: 20px;
 -moz-border-radius:    10px;
 -webkit-border-radius: 10px;
 border-radius:         10px;
}

</style>
</head>
<body>
<div id="wrapper">
    <div id="content">
 <div id="formLogin">
    <table class="formTable">
        <tr>
            <td>Username: </td>
            <td> <input type="text" id="loginusername" name="loginusername"/>  </td>
        </tr>

        <tr>
            <td>Password: </td>
            <td> <input type="password" id="loginpassword" name="loginpassword"/>  </td>
        </tr>

    </table>

    <div align="center">
        <input type="submit" id="btnlogin" name="btnlogin" value="Log In"/>
        <input type="submit" id="btncancelogin" name="btncancelogin" value="Cancel"/>
    </div>
 </div>
    </div>
</div>

</body>
</html>
RandomWhiteTrash
  • 3,974
  • 5
  • 29
  • 42
0

Like Hachi says try text-align:center; but you could also add this to your CSS:

body {
    width:100%;
}

This will give your page a width, so your elements will have a width to use.

Update:

Didn't realise you wanted it vertically centered too. You could put the whole thing in a table cell and use valign="middle" to center it.

Rob
  • 6,304
  • 24
  • 83
  • 189
0

I think it's about DOCTYPE. Have try to put DOCTYPE

HTML 5

<!DOCTYPE HTML>
<html>

HTML 4

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
kst
  • 1,498
  • 3
  • 19
  • 34