Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何在HTML div中间对齐?_Css_Html_Alignment - Fatal编程技术网

Css 如何在HTML div中间对齐?

Css 如何在HTML div中间对齐?,css,html,alignment,Css,Html,Alignment,我一直在谷歌上寻找这个,它说css代码是margin:0auto;。我试过了,但对我不起作用。请帮忙。提前谢谢 login.html 如果你想垂直居中,也可以试着阅读 更新: 试试这个代码。当然,您可以将CSS移出到CSS文件中。在IE9和FF6中测试: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Log In&

我一直在谷歌上寻找这个,它说css代码是margin:0auto;。我试过了,但对我不起作用。请帮忙。提前谢谢

login.html


如果你想垂直居中,也可以试着阅读

更新:

试试这个代码。当然,您可以将CSS移出到CSS文件中。在IE9和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>
就像Hachi说的尝试文本对齐:居中;但您也可以将其添加到CSS中:

body {
    width:100%;
}
这将为您的页面提供一个宽度,因此您的元素将有一个可使用的宽度

更新:

我不知道你也希望它垂直居中。您可以将整个内容放在一个表格单元格中,并使用valign=middle将其居中。

我认为这是关于DOCTYPE的。请试着输入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>

我认为你最好把你的代码示例简化为最基本的形式,并包括一个你想要的示例和一些你已经尝试过的解释。对,你想要完成什么?我希望整个DeValm登录垂直在浏览器的中间。你在浏览什么浏览器?看起来你的代码对我来说很好?带有登录表单的表集中在页面的中间。但不是垂直的。是否要将其垂直居中?
<!DOCTYPE HTML>
<html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>